1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11 
12 // reverse_view() requires default_initializable<V> = default;
13 
14 #include <ranges>
15 #include <cassert>
16 
17 #include "types.h"
18 
19 enum CtorKind { DefaultCtor, PtrCtor };
20 template<CtorKind CK>
21 struct BidirRangeWith : std::ranges::view_base {
22   int *ptr_ = nullptr;
23 
24   constexpr BidirRangeWith() requires (CK == DefaultCtor) = default;
25   constexpr BidirRangeWith(int *ptr);
26 
beginBidirRangeWith27   constexpr bidirectional_iterator<int*> begin() { return bidirectional_iterator<int*>{ptr_}; }
beginBidirRangeWith28   constexpr bidirectional_iterator<const int*> begin() const { return bidirectional_iterator<const int*>{ptr_}; }
endBidirRangeWith29   constexpr bidirectional_iterator<int*> end() { return bidirectional_iterator<int*>{ptr_ + 8}; }
endBidirRangeWith30   constexpr bidirectional_iterator<const int*> end() const { return bidirectional_iterator<const int*>{ptr_ + 8}; }
31 };
32 
test()33 constexpr bool test() {
34   {
35     static_assert( std::default_initializable<std::ranges::reverse_view<BidirRangeWith<DefaultCtor>>>);
36     static_assert(!std::default_initializable<std::ranges::reverse_view<BidirRangeWith<PtrCtor>>>);
37   }
38 
39   {
40     std::ranges::reverse_view<BidirRangeWith<DefaultCtor>> rev;
41     assert(rev.base().ptr_ == nullptr);
42   }
43   {
44     const std::ranges::reverse_view<BidirRangeWith<DefaultCtor>> rev;
45     assert(rev.base().ptr_ == nullptr);
46   }
47 
48   return true;
49 }
50 
main(int,char **)51 int main(int, char**) {
52   test();
53   static_assert(test());
54 
55   return 0;
56 }
57 
58