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