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<MoveOnlyForwardIter, int*> a(MoveOnlyForwardIter(globalBuff), globalBuff + 8, 8); 24 assert(a.begin().base == globalBuff); 25 assert(!a.empty()); 26 assert(a.size() == 8); 27 28 std::ranges::subrange<ForwardIter> b(ForwardIter(nullptr), ForwardIter(nullptr)); 29 assert(b.empty()); 30 31 std::ranges::subrange<ForwardIter> c{ForwardIter(globalBuff), ForwardIter(globalBuff)}; 32 assert(c.empty()); 33 34 std::ranges::subrange<ForwardIter> d(ForwardIter(globalBuff), ForwardIter(globalBuff + 1)); 35 assert(!d.empty()); 36 37 std::ranges::subrange<SizedSentinelForwardIter> e(SizedSentinelForwardIter(globalBuff), 38 SizedSentinelForwardIter(globalBuff + 8), 8); 39 assert(!e.empty()); 40 assert(e.size() == 8); 41 42 // Make sure that operator- is used to calculate size when possible. 43 if (!std::is_constant_evaluated()) 44 assert(SizedSentinelForwardIter::minusCount == 1); 45 46 return true; 47 } 48 49 50 int main(int, char**) { 51 test(); 52 static_assert(test()); 53 54 return 0; 55 } 56