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

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