1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // template <class I1, class I2, class O>
12 // struct in_in_out_result;
16 #include <type_traits>
23 // no implicit conversion
24 static_assert(!std::is_constructible_v
<std::ranges::in_in_out_result
<A
, A
, A
>,
25 std::ranges::in_in_out_result
<int, int, int>>);
30 // implicit conversion
31 static_assert(std::is_constructible_v
<std::ranges::in_in_out_result
<B
, B
, B
>, std::ranges::in_in_out_result
<int, int, int>>);
32 static_assert(std::is_constructible_v
<std::ranges::in_in_out_result
<B
, B
, B
>, std::ranges::in_in_out_result
<int, int, int>&>);
33 static_assert(std::is_constructible_v
<std::ranges::in_in_out_result
<B
, B
, B
>, const std::ranges::in_in_out_result
<int, int, int>>);
34 static_assert(std::is_constructible_v
<std::ranges::in_in_out_result
<B
, B
, B
>, const std::ranges::in_in_out_result
<int, int, int>&>);
39 static_assert(!std::is_constructible_v
<std::ranges::in_in_out_result
<C
, C
, C
>, std::ranges::in_in_out_result
<int, int, int>&>);
41 // has to be convertible via const&
42 static_assert(std::is_convertible_v
<std::ranges::in_in_out_result
<int, int, int>&, std::ranges::in_in_out_result
<long, long, long>>);
43 static_assert(std::is_convertible_v
<const std::ranges::in_in_out_result
<int, int, int>&, std::ranges::in_in_out_result
<long, long, long>>);
44 static_assert(std::is_convertible_v
<std::ranges::in_in_out_result
<int, int, int>&&, std::ranges::in_in_out_result
<long, long, long>>);
45 static_assert(std::is_convertible_v
<const std::ranges::in_in_out_result
<int, int, int>&&, std::ranges::in_in_out_result
<long, long, long>>);
47 // should be move constructible
48 static_assert(std::is_move_constructible_v
<std::ranges::in_in_out_result
<MoveOnly
, int, int>>);
49 static_assert(std::is_move_constructible_v
<std::ranges::in_in_out_result
<int, MoveOnly
, int>>);
50 static_assert(std::is_move_constructible_v
<std::ranges::in_in_out_result
<int, int, MoveOnly
>>);
52 // should not be copy constructible
53 static_assert(!std::is_copy_constructible_v
<std::ranges::in_in_out_result
<MoveOnly
, int, int>>);
54 static_assert(!std::is_copy_constructible_v
<std::ranges::in_in_out_result
<int, MoveOnly
, int>>);
55 static_assert(!std::is_copy_constructible_v
<std::ranges::in_in_out_result
<int, int, MoveOnly
>>);
57 struct NotConvertible
{};
58 // conversions should not work if there is no conversion
59 static_assert(!std::is_convertible_v
<std::ranges::in_in_out_result
<NotConvertible
, int, int>, std::ranges::in_in_out_result
<int, int, int>>);
60 static_assert(!std::is_convertible_v
<std::ranges::in_in_out_result
<int, NotConvertible
, int>, std::ranges::in_in_out_result
<int, int, int>>);
61 static_assert(!std::is_convertible_v
<std::ranges::in_in_out_result
<int, int, NotConvertible
>, std::ranges::in_in_out_result
<int, int, int>>);
64 struct ConvertibleFrom
{
65 constexpr ConvertibleFrom(T c
) : content
{c
} {}
69 constexpr bool test() {
71 std::ranges::in_in_out_result
<int, double, float> res
{10, 0., 1.f
};
72 assert(res
.in1
== 10);
73 assert(res
.in2
== 0.);
74 assert(res
.out
== 1.f
);
75 std::ranges::in_in_out_result
<ConvertibleFrom
<int>, ConvertibleFrom
<double>, ConvertibleFrom
<float>> res2
= res
;
76 assert(res2
.in1
.content
== 10);
77 assert(res2
.in2
.content
== 0.);
78 assert(res2
.out
.content
== 1.f
);
81 std::ranges::in_in_out_result
<MoveOnly
, int, int> res1
{MoveOnly
{}, 0, 0};
82 assert(res1
.in1
.get() == 1);
83 auto res2
= static_cast<std::ranges::in_in_out_result
<MoveOnly
, int, int>>(std::move(res1
));
84 assert(res1
.in1
.get() == 0);
85 assert(res2
.in1
.get() == 1);
88 auto [in1
, in2
, out
] = std::ranges::in_in_out_result
<int, int, int>{1, 2, 3};
96 int main(int, char**) {
98 static_assert(test());