Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / algorithms.results / in_out_result.pass.cpp
blobca9f4464dee5fb4bef31c64dc81c65bc59e76623
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 O1>
12 // struct in_out_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::in_out_result<A, A>, std::ranges::in_out_result<int, int>>);
26 struct B {
27 B(int);
29 // implicit conversion
30 static_assert(std::is_constructible_v<std::ranges::in_out_result<B, B>, std::ranges::in_out_result<int, int>>);
31 static_assert(std::is_constructible_v<std::ranges::in_out_result<B, B>, std::ranges::in_out_result<int, int>&>);
32 static_assert(std::is_constructible_v<std::ranges::in_out_result<B, B>, const std::ranges::in_out_result<int, int>>);
33 static_assert(std::is_constructible_v<std::ranges::in_out_result<B, B>, const std::ranges::in_out_result<int, int>&>);
35 struct C {
36 C(int&);
38 static_assert(!std::is_constructible_v<std::ranges::in_out_result<C, C>, std::ranges::in_out_result<int, int>&>);
40 // has to be convertible via const&
41 static_assert(std::is_convertible_v<std::ranges::in_out_result<int, int>&, std::ranges::in_out_result<long, long>>);
42 static_assert(std::is_convertible_v<const std::ranges::in_out_result<int, int>&, std::ranges::in_out_result<long, long>>);
43 static_assert(std::is_convertible_v<std::ranges::in_out_result<int, int>&&, std::ranges::in_out_result<long, long>>);
44 static_assert(std::is_convertible_v<const std::ranges::in_out_result<int, int>&&, std::ranges::in_out_result<long, long>>);
46 // should be move constructible
47 static_assert(std::is_move_constructible_v<std::ranges::in_out_result<MoveOnly, int>>);
48 static_assert(std::is_move_constructible_v<std::ranges::in_out_result<int, MoveOnly>>);
50 struct NotConvertible {};
51 // conversions should not work if there is no conversion
52 static_assert(!std::is_convertible_v<std::ranges::in_out_result<NotConvertible, int>, std::ranges::in_out_result<int, NotConvertible>>);
53 static_assert(!std::is_convertible_v<std::ranges::in_out_result<int, NotConvertible>, std::ranges::in_out_result<NotConvertible, int>>);
55 template <class T>
56 struct ConvertibleFrom {
57 constexpr ConvertibleFrom(T c) : content{c} {}
58 T content;
61 constexpr bool test() {
63 std::ranges::in_out_result<double, int> res{10, 1};
64 assert(res.in == 10);
65 assert(res.out == 1);
66 std::ranges::in_out_result<ConvertibleFrom<double>, ConvertibleFrom<int>> res2 = res;
67 assert(res2.in.content == 10);
68 assert(res2.out.content == 1);
71 std::ranges::in_out_result<MoveOnly, int> res{MoveOnly{}, 10};
72 assert(res.in.get() == 1);
73 assert(res.out == 10);
74 auto res2 = std::move(res);
75 assert(res.in.get() == 0);
76 assert(res.out == 10);
77 assert(res2.in.get() == 1);
78 assert(res2.out == 10);
81 auto [min, max] = std::ranges::in_out_result<int, int>{1, 2};
82 assert(min == 1);
83 assert(max == 2);
86 return true;
89 int main(int, char**) {
90 test();
91 static_assert(test());
93 return 0;