Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / algorithms.results / in_in_out_result.pass.cpp
blobc9ab2d430b5002ca4e74f30c9ec84f67c1452ba9
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, class O>
12 // struct in_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_in_out_result<A, A, A>,
25 std::ranges::in_in_out_result<int, int, int>>);
27 struct B {
28 B(int);
30 // implicit conversion
31 static_assert(std::is_constructible_v<std::ranges::in_in_out_result<B, B, B>, std::ranges::in_in_out_result<int, int, int>>);
32 static_assert(std::is_constructible_v<std::ranges::in_in_out_result<B, B, B>, std::ranges::in_in_out_result<int, int, int>&>);
33 static_assert(std::is_constructible_v<std::ranges::in_in_out_result<B, B, B>, const std::ranges::in_in_out_result<int, int, int>>);
34 static_assert(std::is_constructible_v<std::ranges::in_in_out_result<B, B, B>, const std::ranges::in_in_out_result<int, int, int>&>);
36 struct C {
37 C(int&);
39 static_assert(!std::is_constructible_v<std::ranges::in_in_out_result<C, C, C>, std::ranges::in_in_out_result<int, int, int>&>);
41 // has to be convertible via const&
42 static_assert(std::is_convertible_v<std::ranges::in_in_out_result<int, int, int>&, std::ranges::in_in_out_result<long, long, long>>);
43 static_assert(std::is_convertible_v<const std::ranges::in_in_out_result<int, int, int>&, std::ranges::in_in_out_result<long, long, long>>);
44 static_assert(std::is_convertible_v<std::ranges::in_in_out_result<int, int, int>&&, std::ranges::in_in_out_result<long, long, long>>);
45 static_assert(std::is_convertible_v<const std::ranges::in_in_out_result<int, int, int>&&, std::ranges::in_in_out_result<long, long, long>>);
47 // should be move constructible
48 static_assert(std::is_move_constructible_v<std::ranges::in_in_out_result<MoveOnly, int, int>>);
49 static_assert(std::is_move_constructible_v<std::ranges::in_in_out_result<int, MoveOnly, int>>);
50 static_assert(std::is_move_constructible_v<std::ranges::in_in_out_result<int, int, MoveOnly>>);
52 // should not be copy constructible
53 static_assert(!std::is_copy_constructible_v<std::ranges::in_in_out_result<MoveOnly, int, int>>);
54 static_assert(!std::is_copy_constructible_v<std::ranges::in_in_out_result<int, MoveOnly, int>>);
55 static_assert(!std::is_copy_constructible_v<std::ranges::in_in_out_result<int, int, MoveOnly>>);
57 struct NotConvertible {};
58 // conversions should not work if there is no conversion
59 static_assert(!std::is_convertible_v<std::ranges::in_in_out_result<NotConvertible, int, int>, std::ranges::in_in_out_result<int, int, int>>);
60 static_assert(!std::is_convertible_v<std::ranges::in_in_out_result<int, NotConvertible, int>, std::ranges::in_in_out_result<int, int, int>>);
61 static_assert(!std::is_convertible_v<std::ranges::in_in_out_result<int, int, NotConvertible>, std::ranges::in_in_out_result<int, int, int>>);
63 template <class T>
64 struct ConvertibleFrom {
65 constexpr ConvertibleFrom(T c) : content{c} {}
66 T content;
69 constexpr bool test() {
71 std::ranges::in_in_out_result<int, double, float> res{10, 0., 1.f};
72 assert(res.in1 == 10);
73 assert(res.in2 == 0.);
74 assert(res.out == 1.f);
75 std::ranges::in_in_out_result<ConvertibleFrom<int>, ConvertibleFrom<double>, ConvertibleFrom<float>> res2 = res;
76 assert(res2.in1.content == 10);
77 assert(res2.in2.content == 0.);
78 assert(res2.out.content == 1.f);
81 std::ranges::in_in_out_result<MoveOnly, int, int> res1{MoveOnly{}, 0, 0};
82 assert(res1.in1.get() == 1);
83 auto res2 = static_cast<std::ranges::in_in_out_result<MoveOnly, int, int>>(std::move(res1));
84 assert(res1.in1.get() == 0);
85 assert(res2.in1.get() == 1);
88 auto [in1, in2, out] = std::ranges::in_in_out_result<int, int, int>{1, 2, 3};
89 assert(in1 == 1);
90 assert(in2 == 2);
91 assert(out == 3);
93 return true;
96 int main(int, char**) {
97 test();
98 static_assert(test());
100 return 0;