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

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