Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / algorithms.results / in_fun_result.pass.cpp
blobf44b5988d849ad7b4af745ba14fb8b718d344869
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 in_fun_result;
14 #include <algorithm>
15 #include <cassert>
16 #include <type_traits>
17 #include <utility>
19 #include "MoveOnly.h"
21 struct A {
22 explicit A(int);
24 // no implicit conversion
25 static_assert(!std::is_constructible_v<std::ranges::in_fun_result<A, A>, std::ranges::in_fun_result<int, int>>);
27 struct B {
28 B(int);
30 // implicit conversion
31 static_assert(std::is_constructible_v<std::ranges::in_fun_result<B, B>, std::ranges::in_fun_result<int, int>>);
32 static_assert(std::is_constructible_v<std::ranges::in_fun_result<B, B>, std::ranges::in_fun_result<int, int>&>);
33 static_assert(std::is_constructible_v<std::ranges::in_fun_result<B, B>, const std::ranges::in_fun_result<int, int>>);
34 static_assert(std::is_constructible_v<std::ranges::in_fun_result<B, B>, const std::ranges::in_fun_result<int, int>&>);
36 struct C {
37 C(int&);
39 static_assert(!std::is_constructible_v<std::ranges::in_fun_result<C, C>, std::ranges::in_fun_result<int, int>&>);
41 // has to be convertible via const&
42 static_assert(std::is_convertible_v<std::ranges::in_fun_result<int, int>&, std::ranges::in_fun_result<long, long>>);
43 static_assert(std::is_convertible_v<const std::ranges::in_fun_result<int, int>&, std::ranges::in_fun_result<long, long>>);
44 static_assert(std::is_convertible_v<std::ranges::in_fun_result<int, int>&&, std::ranges::in_fun_result<long, long>>);
45 static_assert(std::is_convertible_v<const std::ranges::in_fun_result<int, int>&&, std::ranges::in_fun_result<long, long>>);
47 // should be move constructible
48 static_assert(std::is_move_constructible_v<std::ranges::in_fun_result<MoveOnly, int>>);
49 static_assert(std::is_move_constructible_v<std::ranges::in_fun_result<int, MoveOnly>>);
51 // should not copy constructible with move-only type
52 static_assert(!std::is_copy_constructible_v<std::ranges::in_fun_result<MoveOnly, int>>);
53 static_assert(!std::is_copy_constructible_v<std::ranges::in_fun_result<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_fun_result<NotConvertible, int>, std::ranges::in_fun_result<int, int>>);
58 static_assert(!std::is_convertible_v<std::ranges::in_fun_result<int, NotConvertible>, std::ranges::in_fun_result<int, int>>);
60 template <class T>
61 struct ConvertibleFrom {
62 constexpr ConvertibleFrom(T c) : content{c} {}
63 T content;
66 constexpr bool test() {
68 std::ranges::in_fun_result<int, double> res{10, 0.};
69 assert(res.in == 10);
70 assert(res.fun == 0.);
71 std::ranges::in_fun_result<ConvertibleFrom<int>, ConvertibleFrom<double>> res2 = res;
72 assert(res2.in.content == 10);
73 assert(res2.fun.content == 0.);
76 std::ranges::in_fun_result<MoveOnly, int> res{MoveOnly{}, 2};
77 assert(res.in.get() == 1);
78 assert(res.fun == 2);
79 auto res2 = static_cast<std::ranges::in_fun_result<MoveOnly, int>>(std::move(res));
80 assert(res.in.get() == 0);
81 assert(res2.in.get() == 1);
82 assert(res2.fun == 2);
85 auto [in, fun] = std::ranges::in_fun_result<int, int>{1, 2};
86 assert(in == 1);
87 assert(fun == 2);
89 return true;
92 int main(int, char**) {
93 test();
94 static_assert(test());
96 return 0;