| 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 <cassert> |
| 16 | #include "test_macros.h" |
| 17 | #include "test_iterators.h" |
| 18 | #include "types.h" |
| 19 | |
| 20 | constexpr bool test() { |
| 21 | std::ranges::subrange<int*> a(globalBuff, globalBuff + 8, 8); |
| 22 | auto a1 = a.next(); |
| 23 | assert(a1.begin() == globalBuff + 1); |
| 24 | assert(a1.size() == 7); |
| 25 | auto a5 = a.next(5); |
| 26 | assert(a5.begin() == globalBuff + 5); |
| 27 | assert(a5.size() == 3); |
| 28 | auto a4 = a5.prev(); |
| 29 | assert(a4.begin() == globalBuff + 4); |
| 30 | assert(a4.size() == 4); |
| 31 | |
| 32 | std::ranges::subrange<InputIter, sentinel_wrapper<InputIter>> b(InputIter(globalBuff), sentinel_wrapper(InputIter(globalBuff + 8))); |
| 33 | auto b1 = std::move(b).next(); |
| 34 | assert(base(b1.begin()) == globalBuff + 1); |
| 35 | |
| 36 | std::ranges::subrange<BidirIter> c(BidirIter(globalBuff + 4), BidirIter(globalBuff + 8)); |
| 37 | auto c1 = c.prev(); |
| 38 | assert(base(c1.begin()) == globalBuff + 3); |
| 39 | auto c2 = c.prev(4); |
| 40 | assert(base(c2.begin()) == globalBuff); |
| 41 | |
| 42 | std::ranges::subrange<BidirIter> d(BidirIter(globalBuff + 4), BidirIter(globalBuff + 8)); |
| 43 | auto d1 = d.advance(4); |
| 44 | assert(base(d1.begin()) == globalBuff + 8); |
| 45 | assert(d1.empty()); |
| 46 | auto d2 = d1.advance(-4); |
| 47 | assert(base(d2.begin()) == globalBuff + 4); |
| 48 | |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | int main(int, char**) { |
| 53 | test(); |
| 54 | static_assert(test()); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |