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