1
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++03, c++11, c++14, c++17
11
12// template<different-from<subrange> PairLike>
13// requires pair-like-convertible-from<PairLike, const I&, const S&>
14// constexpr operator PairLike() const;
15
16#include <array>
17#include <cassert>
18#include <concepts>
19#include <ranges>
20#include <utility>
21
22#include "test_macros.h"
23
24static_assert(std::convertible_to<std::ranges::subrange<int*>, std::pair<int*, int*>>);
25static_assert(std::convertible_to<std::ranges::subrange<int*>, std::tuple<int*, int*>>);
26static_assert(!std::convertible_to<std::ranges::subrange<int*>, std::pair<long*, int*>>);
27static_assert(!std::convertible_to<std::ranges::subrange<int*>, std::pair<int*, long*>>);
28static_assert(!std::convertible_to<std::ranges::subrange<int*>, std::pair<long*, long*>>);
29static_assert(!std::convertible_to<std::ranges::subrange<int*>, std::array<int*, 2>>);
30
31constexpr bool test() {
32 // Check to std::pair
33 {
34 int data[] = {1, 2, 3, 4, 5};
35 const std::ranges::subrange a(data);
36 {
37 std::pair<int*, int*> p(a);
38 assert(p.first == data + 0);
39 assert(p.second == data + 5);
40 }
41 {
42 std::pair<int*, int*> p{a};
43 assert(p.first == data + 0);
44 assert(p.second == data + 5);
45 }
46 {
47 std::pair<int*, int*> p = a;
48 assert(p.first == data + 0);
49 assert(p.second == data + 5);
50 }
51 }
52
53 // Check to std::tuple
54 {
55 int data[] = {1, 2, 3, 4, 5};
56 const std::ranges::subrange a(data);
57 {
58 std::tuple<int*, int*> p(a);
59 assert(std::get<0>(p) == data + 0);
60 assert(std::get<1>(p) == data + 5);
61 }
62 {
63 std::tuple<int*, int*> p{a};
64 assert(std::get<0>(p) == data + 0);
65 assert(std::get<1>(p) == data + 5);
66 }
67 {
68 std::tuple<int*, int*> p = a;
69 assert(std::get<0>(p) == data + 0);
70 assert(std::get<1>(p) == data + 5);
71 }
72 }
73
74 return true;
75}
76
77int main(int, char**) {
78 test();
79 static_assert(test());
80
81 return 0;
82}
83

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