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>
12 // struct in_fun_result;
16 #include <type_traits>
24 // no implicit conversion
25 static_assert(!std::is_constructible_v
<std::ranges::in_fun_result
<A
, A
>, std::ranges::in_fun_result
<int, int>>);
30 // implicit conversion
31 static_assert(std::is_constructible_v
<std::ranges::in_fun_result
<B
, B
>, std::ranges::in_fun_result
<int, int>>);
32 static_assert(std::is_constructible_v
<std::ranges::in_fun_result
<B
, B
>, std::ranges::in_fun_result
<int, int>&>);
33 static_assert(std::is_constructible_v
<std::ranges::in_fun_result
<B
, B
>, const std::ranges::in_fun_result
<int, int>>);
34 static_assert(std::is_constructible_v
<std::ranges::in_fun_result
<B
, B
>, const std::ranges::in_fun_result
<int, int>&>);
39 static_assert(!std::is_constructible_v
<std::ranges::in_fun_result
<C
, C
>, std::ranges::in_fun_result
<int, int>&>);
41 // has to be convertible via const&
42 static_assert(std::is_convertible_v
<std::ranges::in_fun_result
<int, int>&, std::ranges::in_fun_result
<long, long>>);
43 static_assert(std::is_convertible_v
<const std::ranges::in_fun_result
<int, int>&, std::ranges::in_fun_result
<long, long>>);
44 static_assert(std::is_convertible_v
<std::ranges::in_fun_result
<int, int>&&, std::ranges::in_fun_result
<long, long>>);
45 static_assert(std::is_convertible_v
<const std::ranges::in_fun_result
<int, int>&&, std::ranges::in_fun_result
<long, long>>);
47 // should be move constructible
48 static_assert(std::is_move_constructible_v
<std::ranges::in_fun_result
<MoveOnly
, int>>);
49 static_assert(std::is_move_constructible_v
<std::ranges::in_fun_result
<int, MoveOnly
>>);
51 // should not copy constructible with move-only type
52 static_assert(!std::is_copy_constructible_v
<std::ranges::in_fun_result
<MoveOnly
, int>>);
53 static_assert(!std::is_copy_constructible_v
<std::ranges::in_fun_result
<int, MoveOnly
>>);
55 struct NotConvertible
{};
56 // conversions should not work if there is no conversion
57 static_assert(!std::is_convertible_v
<std::ranges::in_fun_result
<NotConvertible
, int>, std::ranges::in_fun_result
<int, int>>);
58 static_assert(!std::is_convertible_v
<std::ranges::in_fun_result
<int, NotConvertible
>, std::ranges::in_fun_result
<int, int>>);
61 struct ConvertibleFrom
{
62 constexpr ConvertibleFrom(T c
) : content
{c
} {}
66 constexpr bool test() {
68 std::ranges::in_fun_result
<int, double> res
{10, 0.};
70 assert(res
.fun
== 0.);
71 std::ranges::in_fun_result
<ConvertibleFrom
<int>, ConvertibleFrom
<double>> res2
= res
;
72 assert(res2
.in
.content
== 10);
73 assert(res2
.fun
.content
== 0.);
76 std::ranges::in_fun_result
<MoveOnly
, int> res
{MoveOnly
{}, 2};
77 assert(res
.in
.get() == 1);
79 auto res2
= static_cast<std::ranges::in_fun_result
<MoveOnly
, int>>(std::move(res
));
80 assert(res
.in
.get() == 0);
81 assert(res2
.in
.get() == 1);
82 assert(res2
.fun
== 2);
85 auto [in
, fun
] = std::ranges::in_fun_result
<int, int>{1, 2};
92 int main(int, char**) {
94 static_assert(test());