Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / algorithms.results / in_out_out_result.pass.cpp
blob682462bc9a5ba13fb3c3fe541cc4ec6fd3bdb226
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, class O2>
12 // struct in_out_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_out_result<A, A, A>, std::ranges::in_out_out_result<int, int, int>>);
26 struct B {
27 B(int);
29 // implicit conversion
30 static_assert(std::is_constructible_v<std::ranges::in_out_out_result<B, B, B>, std::ranges::in_out_out_result<int, int, int>>);
31 static_assert(std::is_constructible_v<std::ranges::in_out_out_result<B, B, B>, std::ranges::in_out_out_result<int, int, int>&>);
32 static_assert(std::is_constructible_v<std::ranges::in_out_out_result<B, B, B>, const std::ranges::in_out_out_result<int, int, int>>);
33 static_assert(std::is_constructible_v<std::ranges::in_out_out_result<B, B, B>, const std::ranges::in_out_out_result<int, int, int>&>);
35 struct C {
36 C(int&);
38 static_assert(!std::is_constructible_v<std::ranges::in_out_out_result<C, C, C>, std::ranges::in_out_out_result<int, int, int>&>);
40 // has to be convertible via const&
41 static_assert(std::is_convertible_v<std::ranges::in_out_out_result<int, int, int>&, std::ranges::in_out_out_result<long, long, long>>);
42 static_assert(std::is_convertible_v<const std::ranges::in_out_out_result<int, int, int>&, std::ranges::in_out_out_result<long, long, long>>);
43 static_assert(std::is_convertible_v<std::ranges::in_out_out_result<int, int, int>&&, std::ranges::in_out_out_result<long, long, long>>);
44 static_assert(std::is_convertible_v<const std::ranges::in_out_out_result<int, int, int>&&, std::ranges::in_out_out_result<long, long, long>>);
46 // should be move constructible
47 static_assert(std::is_move_constructible_v<std::ranges::in_out_out_result<MoveOnly, int, int>>);
48 static_assert(std::is_move_constructible_v<std::ranges::in_out_out_result<int, MoveOnly, int>>);
49 static_assert(std::is_move_constructible_v<std::ranges::in_out_out_result<int, int, MoveOnly>>);
51 static_assert(!std::is_copy_constructible_v<std::ranges::in_out_out_result<MoveOnly, int, int>>);
52 static_assert(!std::is_copy_constructible_v<std::ranges::in_out_out_result<int, MoveOnly, int>>);
53 static_assert(!std::is_copy_constructible_v<std::ranges::in_out_out_result<int, 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_out_out_result<NotConvertible, int, int>, std::ranges::in_out_out_result<int, int, int>>);
58 static_assert(!std::is_convertible_v<std::ranges::in_out_out_result<int, NotConvertible, int>, std::ranges::in_out_out_result<int, int, int>>);
59 static_assert(!std::is_convertible_v<std::ranges::in_out_out_result<int, int, NotConvertible>, std::ranges::in_out_out_result<int, int, int>>);
61 template <class T>
62 struct ConvertibleFrom {
63 constexpr ConvertibleFrom(T c) : content{c} {}
64 T content;
67 constexpr bool test() {
69 std::ranges::in_out_out_result<int, double, float> res{10, 0., 1.f};
70 assert(res.in == 10);
71 assert(res.out1 == 0.);
72 assert(res.out2 == 1.f);
73 std::ranges::in_out_out_result<ConvertibleFrom<int>, ConvertibleFrom<double>, ConvertibleFrom<float>> res2 = res;
74 assert(res2.in.content == 10);
75 assert(res2.out1.content == 0.);
76 assert(res2.out2.content == 1.f);
79 std::ranges::in_out_out_result<MoveOnly, int, int> res1{MoveOnly{}, 0, 0};
80 assert(res1.in.get() == 1);
81 auto res2 = static_cast<std::ranges::in_out_out_result<MoveOnly, int, int>>(std::move(res1));
82 assert(res1.in.get() == 0);
83 assert(res2.in.get() == 1);
86 auto [in, out1, out2] = std::ranges::in_out_out_result<int, int, int>{1, 2, 3};
87 assert(in == 1);
88 assert(out1 == 2);
89 assert(out2 == 3);
91 return true;
94 int main(int, char**) {
95 test();
96 static_assert(test());
98 return 0;