Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / algorithms.results / min_max_result.pass.cpp
blob23c22ec9d3924a19b1c9df8acb21e7ef452af61c
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // template <class I1, class I2>
12 // struct min_max_result;
14 #include <algorithm>
15 #include <cassert>
16 #include <type_traits>
18 #include "MoveOnly.h"
20 struct A {
21 explicit A(int);
23 // no implicit conversion
24 static_assert(!std::is_constructible_v<std::ranges::min_max_result<A>, std::ranges::min_max_result<int>>);
26 struct B {
27 B(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>&>);
35 struct C {
36 C(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>>);
56 template <class T>
57 struct ConvertibleFrom {
58 constexpr ConvertibleFrom(T c) : content{c} {}
59 T content;
62 constexpr bool test() {
64 std::ranges::min_max_result<double> res{10, 1};
65 assert(res.min == 10);
66 assert(res.max == 1);
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};
83 assert(min == 1);
84 assert(max == 2);
87 return true;
90 int main(int, char**) {
91 test();
92 static_assert(test());
94 return 0;