[RISCV] Add RVVConstraint to SiFive custom matrix multiply instructions. (#124055)
[llvm-project.git] / libcxx / test / std / algorithms / algorithms.results / in_value_result.pass.cpp
blobb7aba0c88ee950e2ba4a7442d6725696fa03532a
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, c++20
11 // template <class I, class T>
12 // struct in_value_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_value_result<A, A>, std::ranges::in_value_result<int, int>>);
27 struct B {
28 B(int);
30 // implicit conversion
31 static_assert(std::is_constructible_v<std::ranges::in_value_result<B, B>, std::ranges::in_value_result<int, int>>);
32 static_assert(std::is_constructible_v<std::ranges::in_value_result<B, B>, std::ranges::in_value_result<int, int>&>);
33 static_assert(
34 std::is_constructible_v<std::ranges::in_value_result<B, B>, const std::ranges::in_value_result<int, int>>);
35 static_assert(
36 std::is_constructible_v<std::ranges::in_value_result<B, B>, const std::ranges::in_value_result<int, int>&>);
38 struct C {
39 C(int&);
41 static_assert(!std::is_constructible_v<std::ranges::in_value_result<C, C>, std::ranges::in_value_result<int, int>&>);
43 // has to be convertible via const&
44 static_assert(std::is_convertible_v<std::ranges::in_value_result<int, int>&, std::ranges::in_value_result<long, long>>);
45 static_assert(
46 std::is_convertible_v<const std::ranges::in_value_result<int, int>&, std::ranges::in_value_result<long, long>>);
47 static_assert(
48 std::is_convertible_v<std::ranges::in_value_result<int, int>&&, std::ranges::in_value_result<long, long>>);
49 static_assert(
50 std::is_convertible_v<const std::ranges::in_value_result<int, int>&&, std::ranges::in_value_result<long, long>>);
52 // should be move constructible
53 static_assert(std::is_move_constructible_v<std::ranges::in_value_result<MoveOnly, int>>);
54 static_assert(std::is_move_constructible_v<std::ranges::in_value_result<int, MoveOnly>>);
56 // should not be copy constructible with move-only type
57 static_assert(!std::is_copy_constructible_v<std::ranges::in_value_result<MoveOnly, int>>);
58 static_assert(!std::is_copy_constructible_v<std::ranges::in_value_result<int, MoveOnly>>);
60 struct NotConvertible {};
61 // conversions should not work if there is no conversion
62 static_assert(
63 !std::is_convertible_v<std::ranges::in_value_result<NotConvertible, int>, std::ranges::in_value_result<int, int>>);
64 static_assert(
65 !std::is_convertible_v<std::ranges::in_value_result<int, NotConvertible>, std::ranges::in_value_result<int, int>>);
67 template <class T>
68 struct ConvertibleFrom {
69 constexpr ConvertibleFrom(T c) : content{c} {}
70 T content;
73 constexpr bool test() {
74 // Checks that conversion operations are correct.
76 std::ranges::in_value_result<int, double> res{10, 0.};
77 assert(res.in == 10);
78 assert(res.value == 0.);
79 std::ranges::in_value_result<ConvertibleFrom<int>, ConvertibleFrom<double>> res2 = res;
80 assert(res2.in.content == 10);
81 assert(res2.value.content == 0.);
84 // Checks that conversions are possible when one of the types is move-only.
86 std::ranges::in_value_result<MoveOnly, int> res{MoveOnly{}, 2};
87 assert(res.in.get() == 1);
88 assert(res.value == 2);
89 auto res2 = static_cast<std::ranges::in_value_result<MoveOnly, int>>(std::move(res));
90 assert(res.in.get() == 0);
91 assert(res2.in.get() == 1);
92 assert(res2.value == 2);
95 // Checks that structured bindings get the correct values.
97 auto [in, value] = std::ranges::in_value_result<int, int>{1, 2};
98 assert(in == 1);
99 assert(value == 2);
101 return true;
104 int main(int, char**) {
105 test();
106 static_assert(test());
108 return 0;