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-no-concepts
11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
12 
13 // reverse_view() requires default_­initializable<V> = default;
14 
15 #include <ranges>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "types.h"
20 
21 enum CtorKind { DefaultCtor, PtrCtor };
22 template<CtorKind CK>
23 struct BidirRangeWith : std::ranges::view_base {
24   int *ptr_ = nullptr;
25 
26   constexpr BidirRangeWith() requires (CK == DefaultCtor) = default;
27   constexpr BidirRangeWith(int *ptr);
28 
29   constexpr bidirectional_iterator<int*> begin() { return bidirectional_iterator<int*>{ptr_}; }
30   constexpr bidirectional_iterator<const int*> begin() const { return bidirectional_iterator<const int*>{ptr_}; }
31   constexpr bidirectional_iterator<int*> end() { return bidirectional_iterator<int*>{ptr_ + 8}; }
32   constexpr bidirectional_iterator<const int*> end() const { return bidirectional_iterator<const int*>{ptr_ + 8}; }
33 };
34 
35 constexpr bool test() {
36   {
37     static_assert( std::default_initializable<std::ranges::reverse_view<BidirRangeWith<DefaultCtor>>>);
38     static_assert(!std::default_initializable<std::ranges::reverse_view<BidirRangeWith<PtrCtor>>>);
39   }
40 
41   {
42     std::ranges::reverse_view<BidirRangeWith<DefaultCtor>> rev;
43     assert(rev.base().ptr_ == nullptr);
44   }
45   {
46     const std::ranges::reverse_view<BidirRangeWith<DefaultCtor>> rev;
47     assert(rev.base().ptr_ == nullptr);
48   }
49 
50   return true;
51 }
52 
53 int main(int, char**) {
54   test();
55   static_assert(test());
56 
57   return 0;
58 }
59 
60