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 // class std::ranges::subrange; 14 15 #include <ranges> 16 17 #include "types.h" 18 #include <cassert> 19 #include "test_macros.h" 20 #include "test_iterators.h" 21 22 static_assert( std::is_constructible_v<ForwardSubrange, ForwardBorrowedRange>); // Default case. 23 static_assert(!std::is_constructible_v<ForwardSubrange, ForwardRange>); // Not borrowed. 24 // Iter convertible to sentinel (pointer) type. 25 static_assert( std::is_constructible_v<ConvertibleForwardSubrange, ConvertibleForwardBorrowedRange>); 26 // Where neither iter or sentinel are pointers, but they are different. 27 static_assert( std::is_constructible_v<DifferentSentinelSubrange, ForwardBorrowedRangeDifferentSentinel>); 28 static_assert( std::is_constructible_v<DifferentSentinelWithSizeMemberSubrange, DifferentSentinelWithSizeMember>); 29 30 constexpr bool test() { 31 ForwardSubrange a{ForwardBorrowedRange()}; 32 assert(a.begin().base() == globalBuff); 33 assert(a.end().base() == globalBuff + 8); 34 35 ConvertibleForwardSubrange b{ConvertibleForwardBorrowedRange()}; 36 assert(b.begin() == globalBuff); 37 assert(b.end() == globalBuff + 8); 38 39 DifferentSentinelSubrange c{ForwardBorrowedRangeDifferentSentinel()}; 40 assert(c.begin().base() == globalBuff); 41 assert(c.end().value == globalBuff + 8); 42 43 return true; 44 } 45 46 int main(int, char**) { 47 test(); 48 static_assert(test()); 49 50 return 0; 51 } 52