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