1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // struct in_found_result;
16 #include <type_traits>
23 // no implicit conversion
24 static_assert(!std::is_constructible_v
<std::ranges::in_found_result
<A
>, std::ranges::in_found_result
<int>>);
30 // implicit conversion
31 static_assert(std::is_constructible_v
<std::ranges::in_found_result
<B
>, std::ranges::in_found_result
<int>>);
32 static_assert(std::is_constructible_v
<std::ranges::in_found_result
<B
>, std::ranges::in_found_result
<int>&>);
33 static_assert(std::is_constructible_v
<std::ranges::in_found_result
<B
>, const std::ranges::in_found_result
<int>>);
34 static_assert(std::is_constructible_v
<std::ranges::in_found_result
<B
>, const std::ranges::in_found_result
<int>&>);
39 static_assert(!std::is_constructible_v
<std::ranges::in_found_result
<C
>, std::ranges::in_found_result
<int>&>);
41 // has to be convertible via const&
42 static_assert(std::is_convertible_v
<std::ranges::in_found_result
<int>&, std::ranges::in_found_result
<long>>);
43 static_assert(std::is_convertible_v
<const std::ranges::in_found_result
<int>&, std::ranges::in_found_result
<long>>);
44 static_assert(std::is_convertible_v
<std::ranges::in_found_result
<int>&&, std::ranges::in_found_result
<long>>);
45 static_assert(std::is_convertible_v
<const std::ranges::in_found_result
<int>&&, std::ranges::in_found_result
<long>>);
47 // should be move constructible
48 static_assert(std::is_move_constructible_v
<std::ranges::in_found_result
<MoveOnly
>>);
50 // should not be copy constructible
51 static_assert(!std::is_copy_constructible_v
<std::ranges::in_found_result
<MoveOnly
>>);
53 struct NotConvertible
{};
54 // conversions should not work if there is no conversion
55 static_assert(!std::is_convertible_v
<std::ranges::in_found_result
<NotConvertible
>, std::ranges::in_found_result
<int>>);
57 static_assert(std::is_same_v
<decltype(std::ranges::in_found_result
<int>::in
), int>);
58 static_assert(std::is_same_v
<decltype(std::ranges::in_found_result
<int>::found
), bool>);
61 struct ConvertibleFrom
{
62 constexpr ConvertibleFrom(T c
) : content
{c
} {}
66 constexpr bool test() {
68 std::ranges::in_found_result
<double> res
{10, true};
70 assert(res
.found
== true);
71 std::ranges::in_found_result
<ConvertibleFrom
<int>> res2
= res
;
72 assert(res2
.in
.content
== 10);
73 assert(res2
.found
== true);
76 std::ranges::in_found_result
<MoveOnly
> res
{MoveOnly
{}, false};
77 assert(res
.in
.get() == 1);
79 auto res2
= std::move(res
);
80 assert(res2
.in
.get() == 1);
82 assert(res
.in
.get() == 0);
85 auto [in
, found
] = std::ranges::in_found_result
<int>{2, false};
92 int main(int, char**) {
94 static_assert(test());