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