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 min_max_result;
16 #include <type_traits>
23 // no implicit conversion
24 static_assert(!std::is_constructible_v
<std::ranges::min_max_result
<A
>, std::ranges::min_max_result
<int>>);
29 // implicit conversion
30 static_assert(std::is_constructible_v
<std::ranges::min_max_result
<B
>, std::ranges::min_max_result
<int>>);
31 static_assert(std::is_constructible_v
<std::ranges::min_max_result
<B
>, std::ranges::min_max_result
<int>&>);
32 static_assert(std::is_constructible_v
<std::ranges::min_max_result
<B
>, const std::ranges::min_max_result
<int>>);
33 static_assert(std::is_constructible_v
<std::ranges::min_max_result
<B
>, const std::ranges::min_max_result
<int>&>);
38 static_assert(!std::is_constructible_v
<std::ranges::min_max_result
<C
>, std::ranges::min_max_result
<int>&>);
40 // has to be convertible via const&
41 static_assert(std::is_convertible_v
<std::ranges::min_max_result
<int>&, std::ranges::min_max_result
<long>>);
42 static_assert(std::is_convertible_v
<const std::ranges::min_max_result
<int>&, std::ranges::min_max_result
<long>>);
43 static_assert(std::is_convertible_v
<std::ranges::min_max_result
<int>&&, std::ranges::min_max_result
<long>>);
44 static_assert(std::is_convertible_v
<const std::ranges::min_max_result
<int>&&, std::ranges::min_max_result
<long>>);
46 // should be move constructible
47 static_assert(std::is_move_constructible_v
<std::ranges::min_max_result
<MoveOnly
>>);
49 // should not be copy constructible
50 static_assert(!std::is_copy_constructible_v
<std::ranges::min_max_result
<MoveOnly
>>);
52 struct NotConvertible
{};
53 // conversions should not work if there is no conversion
54 static_assert(!std::is_convertible_v
<std::ranges::min_max_result
<NotConvertible
>, std::ranges::min_max_result
<int>>);
57 struct ConvertibleFrom
{
58 constexpr ConvertibleFrom(T c
) : content
{c
} {}
62 constexpr bool test() {
63 // Checks that conversion operations are correct.
65 std::ranges::min_max_result
<double> res
{10, 1};
66 assert(res
.min
== 10);
68 std::ranges::min_max_result
<ConvertibleFrom
<int>> res2
= res
;
69 assert(res2
.min
.content
== 10);
70 assert(res2
.max
.content
== 1);
73 // Checks that conversions are possible when one of the types is move-only.
75 std::ranges::min_max_result
<MoveOnly
> res
{MoveOnly
{}, MoveOnly
{}};
76 assert(res
.min
.get() == 1);
77 assert(res
.max
.get() == 1);
78 auto res2
= std::move(res
);
79 assert(res
.min
.get() == 0);
80 assert(res
.max
.get() == 0);
81 assert(res2
.min
.get() == 1);
82 assert(res2
.max
.get() == 1);
85 // Checks that structured bindings get the correct values.
87 auto [min
, max
] = std::ranges::min_max_result
<int>{1, 2};
95 int main(int, char**) {
97 static_assert(test());