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