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() {
64 std::ranges::min_max_result
<double> res
{10, 1};
65 assert(res
.min
== 10);
67 std::ranges::min_max_result
<ConvertibleFrom
<int>> res2
= res
;
68 assert(res2
.min
.content
== 10);
69 assert(res2
.max
.content
== 1);
72 std::ranges::min_max_result
<MoveOnly
> res
{MoveOnly
{}, MoveOnly
{}};
73 assert(res
.min
.get() == 1);
74 assert(res
.max
.get() == 1);
75 auto res2
= std::move(res
);
76 assert(res
.min
.get() == 0);
77 assert(res
.max
.get() == 0);
78 assert(res2
.min
.get() == 1);
79 assert(res2
.max
.get() == 1);
82 auto [min
, max
] = std::ranges::min_max_result
<int>{1, 2};
90 int main(int, char**) {
92 static_assert(test());