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#include <cassert>
15#include <iterator>
16
17#include "test_iterators.h"
18#include "type_algorithms.h"
19
20template <class Iterator, class Sentinel>
21constexpr bool test() {
22 using Subrange = std::ranges::subrange<Iterator, Sentinel>;
23
24 // Empty subrange
25 {
26 int array[10] = {};
27 Subrange rng(Iterator(std::begin(array)), Sentinel(Iterator(std::begin(array))));
28 std::same_as<Iterator> decltype(auto) beg = rng.begin();
29 std::same_as<Sentinel> decltype(auto) end = rng.end();
30 assert(beg == Iterator(std::begin(array)));
31 assert(end == Iterator(std::begin(array)));
32 }
33
34 // Non-empty subrange
35 {
36 int array[10] = {};
37 Subrange rng(Iterator(std::begin(array)), Sentinel(Iterator(std::end(array) - 3)));
38 std::same_as<Iterator> decltype(auto) beg = rng.begin();
39 std::same_as<Sentinel> decltype(auto) end = rng.end();
40 assert(beg == Iterator(std::begin(array)));
41 assert(end == Iterator(std::end(array) - 3));
42 }
43
44 return true;
45}
46
47int main(int, char**) {
48 types::for_each(types::forward_iterator_list<int*>{}, []<class Iterator> {
49 test<Iterator, sentinel_wrapper<Iterator>>();
50 static_assert(test<Iterator, sentinel_wrapper<Iterator>>());
51 });
52
53 return 0;
54}
55

source code of libcxx/test/std/ranges/range.utility/range.subrange/begin_end.pass.cpp