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: gcc-10 12 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 13 14 // class std::ranges::subrange; 15 16 #include <ranges> 17 18 #include <cassert> 19 #include "test_macros.h" 20 #include "test_iterators.h" 21 22 using FI = forward_iterator<int*>; 23 FI fi{nullptr}; 24 int *ptr = nullptr; 25 26 static_assert(std::same_as<decltype(std::ranges::subrange(fi, fi)), 27 std::ranges::subrange<FI, FI, std::ranges::subrange_kind::unsized>>); 28 static_assert(std::same_as<decltype(std::ranges::subrange(ptr, ptr, 0)), 29 std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>>); 30 static_assert(std::same_as<decltype(std::ranges::subrange(ptr, nullptr, 0)), 31 std::ranges::subrange<int*, nullptr_t, std::ranges::subrange_kind::sized>>); 32 33 struct ForwardRange { 34 forward_iterator<int*> begin() const; 35 forward_iterator<int*> end() const; 36 }; 37 template<> 38 inline constexpr bool std::ranges::enable_borrowed_range<ForwardRange> = true; 39 40 struct SizedRange { 41 int *begin(); 42 int *end(); 43 }; 44 template<> 45 inline constexpr bool std::ranges::enable_borrowed_range<SizedRange> = true; 46 47 static_assert(std::same_as<decltype(std::ranges::subrange(ForwardRange())), 48 std::ranges::subrange<FI, FI, std::ranges::subrange_kind::unsized>>); 49 static_assert(std::same_as<decltype(std::ranges::subrange(SizedRange())), 50 std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>>); 51 static_assert(std::same_as<decltype(std::ranges::subrange(SizedRange(), 8)), 52 std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>>); 53