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