xref: /llvm-project/libcxx/test/std/ranges/range.utility/range.dangling/borrowed_subrange.compile.pass.cpp (revision b8cb1dc9ea87faa8e8e9ab7a31710a8c0bb8b084)
1*74fd3cb8SChristopher Di Bella //===----------------------------------------------------------------------===//
2*74fd3cb8SChristopher Di Bella //
3*74fd3cb8SChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*74fd3cb8SChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information.
5*74fd3cb8SChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*74fd3cb8SChristopher Di Bella //
7*74fd3cb8SChristopher Di Bella //===----------------------------------------------------------------------===//
8*74fd3cb8SChristopher Di Bella 
9*74fd3cb8SChristopher Di Bella // UNSUPPORTED: c++03, c++11, c++14, c++17
10*74fd3cb8SChristopher Di Bella 
11*74fd3cb8SChristopher Di Bella // std::ranges::borrowed_subrange_t;
12*74fd3cb8SChristopher Di Bella 
13*74fd3cb8SChristopher Di Bella #include <ranges>
14*74fd3cb8SChristopher Di Bella 
15*74fd3cb8SChristopher Di Bella #include <concepts>
16*74fd3cb8SChristopher Di Bella #include <span>
17*74fd3cb8SChristopher Di Bella #include <string>
18*74fd3cb8SChristopher Di Bella #include <string_view>
19*74fd3cb8SChristopher Di Bella #include <vector>
20*74fd3cb8SChristopher Di Bella 
21*74fd3cb8SChristopher Di Bella static_assert(std::same_as<std::ranges::borrowed_subrange_t<std::string>, std::ranges::dangling>);
22*74fd3cb8SChristopher Di Bella static_assert(std::same_as<std::ranges::borrowed_subrange_t<std::string&&>, std::ranges::dangling>);
23*74fd3cb8SChristopher Di Bella static_assert(std::same_as<std::ranges::borrowed_subrange_t<std::vector<int> >, std::ranges::dangling>);
24*74fd3cb8SChristopher Di Bella 
25*74fd3cb8SChristopher Di Bella static_assert(
26*74fd3cb8SChristopher Di Bella     std::same_as<std::ranges::borrowed_subrange_t<std::string&>, std::ranges::subrange<std::string::iterator> >);
27*74fd3cb8SChristopher Di Bella 
28*74fd3cb8SChristopher Di Bella static_assert(
29*74fd3cb8SChristopher Di Bella     std::same_as<std::ranges::borrowed_subrange_t<std::span<int> >, std::ranges::subrange<std::span<int>::iterator> >);
30*74fd3cb8SChristopher Di Bella 
31*74fd3cb8SChristopher Di Bella static_assert(std::same_as<std::ranges::borrowed_subrange_t<std::string_view>,
32*74fd3cb8SChristopher Di Bella                            std::ranges::subrange<std::string_view::iterator> >);
33*74fd3cb8SChristopher Di Bella 
34*74fd3cb8SChristopher Di Bella template <class T>
35*74fd3cb8SChristopher Di Bella constexpr bool has_type = requires {
36*74fd3cb8SChristopher Di Bella   typename std::ranges::borrowed_subrange_t<T>;
37*74fd3cb8SChristopher Di Bella };
38*74fd3cb8SChristopher Di Bella 
39*74fd3cb8SChristopher Di Bella static_assert(!has_type<int>);
40*74fd3cb8SChristopher Di Bella 
41*74fd3cb8SChristopher Di Bella struct S {};
42*74fd3cb8SChristopher Di Bella static_assert(!has_type<S>);
43