|
1 | | -#ifndef IRIS_RVARIANT_DETAIL_VARIANT_REQUIREMENTS_HPP |
| 1 | +#ifndef IRIS_RVARIANT_DETAIL_VARIANT_REQUIREMENTS_HPP |
2 | 2 | #define IRIS_RVARIANT_DETAIL_VARIANT_REQUIREMENTS_HPP |
3 | 3 |
|
4 | 4 | // SPDX-License-Identifier: MIT |
|
9 | 9 |
|
10 | 10 | namespace iris::detail { |
11 | 11 |
|
12 | | -template<class T, class U> |
13 | | -struct check_recursive_wrapper_duplicate_impl : std::true_type {}; |
14 | | - |
15 | | -template<class T, class Allocator> |
16 | | -struct check_recursive_wrapper_duplicate_impl<recursive_wrapper<T, Allocator>, T> |
17 | | - : std::false_type |
18 | | -{ |
19 | | - // ReSharper disable once CppStaticAssertFailure |
20 | | - static_assert( |
21 | | - false, |
22 | | - "rvariant cannot contain both `T` and `recursive_wrapper<T, Allocator>` " |
23 | | - "([rvariant.rvariant.general])." |
24 | | - ); |
25 | | -}; |
26 | | - |
27 | | -template<class T, class Allocator> |
28 | | -struct check_recursive_wrapper_duplicate_impl<T, recursive_wrapper<T, Allocator>> |
29 | | - : std::false_type |
30 | | -{ |
31 | | - // ReSharper disable once CppStaticAssertFailure |
32 | | - static_assert( |
33 | | - false, |
34 | | - "rvariant cannot contain both `T` and `recursive_wrapper<T, Allocator>` " |
35 | | - "([rvariant.rvariant.general])." |
36 | | - ); |
37 | | -}; |
38 | | - |
39 | | -template<class T, class Allocator, class UAllocator> |
40 | | - requires (!std::is_same_v<Allocator, UAllocator>) |
41 | | -struct check_recursive_wrapper_duplicate_impl<recursive_wrapper<T, Allocator>, recursive_wrapper<T, UAllocator>> |
42 | | - : std::false_type |
43 | | -{ |
44 | | - // ReSharper disable once CppStaticAssertFailure |
45 | | - static_assert( |
46 | | - false, |
47 | | - "rvariant cannot contain multiple different allocator specializations of " |
48 | | - "`recursive_wrapper` for the same `T` ([rvariant.rvariant.general])." |
49 | | - ); |
50 | | -}; |
51 | | - |
52 | | -template<class T, class... Ts> |
53 | | -struct check_recursive_wrapper_duplicate : std::true_type {}; |
54 | | - |
55 | | -template<class T, class... Ts> requires (sizeof...(Ts) > 0) |
56 | | -struct check_recursive_wrapper_duplicate<T, T, Ts...> |
57 | | - : std::conjunction<check_recursive_wrapper_duplicate_impl<T, Ts>...> |
58 | | -{}; |
59 | | - |
60 | | -template<class T, class List> |
61 | | -struct non_wrapped_exactly_once : exactly_once<T, List> |
62 | | -{ |
63 | | - static_assert( |
64 | | - !is_ttp_specialization_of_v<T, recursive_wrapper>, |
65 | | - "Constructing a `recursive_wrapper` alternative with its full type as the tag is " |
66 | | - "prohibited to avoid confusion; just specify `T` instead." |
67 | | - ); |
68 | | -}; |
69 | | - |
70 | | -template<class T, class List> |
71 | | -constexpr bool non_wrapped_exactly_once_v = non_wrapped_exactly_once<T, List>::value; |
72 | | - |
73 | | - |
74 | | -template<class T, class Variant> |
75 | | -struct exactly_once_index |
76 | | -{ |
77 | | - static_assert(exactly_once_v<T, typename Variant::unwrapped_types>, "T or recursive_wrapper<T> must occur exactly once in Ts..."); |
78 | | - static constexpr std::size_t value = find_index_v<T, typename Variant::unwrapped_types>; |
79 | | -}; |
80 | | - |
81 | | -template<class T, class Variant> |
82 | | -inline constexpr std::size_t exactly_once_index_v = exactly_once_index<T, Variant>::value; |
83 | | - |
84 | | - |
85 | | -template<class T, class U = T const&> |
86 | | -struct variant_copy_assignable : std::conjunction<std::is_constructible<T, U>, std::is_assignable<T&, U>> |
87 | | -{ |
88 | | - static_assert(!std::is_reference_v<T>); |
89 | | - static_assert(std::is_lvalue_reference_v<U>); |
90 | | -}; |
91 | | - |
92 | | -template<class T, class U = T const&> |
93 | | -struct variant_nothrow_copy_assignable : std::conjunction<std::is_nothrow_constructible<T, U>, std::is_nothrow_assignable<T&, U>> |
94 | | -{ |
95 | | - static_assert(!std::is_reference_v<T>); |
96 | | - static_assert(std::is_lvalue_reference_v<U>); |
97 | | - static_assert(variant_copy_assignable<T, U>::value); |
98 | | -}; |
99 | | - |
100 | | -template<class T, class U = T&&> |
101 | | -struct variant_move_assignable : std::conjunction<std::is_constructible<T, U>, std::is_assignable<T&, U>> |
102 | | -{ |
103 | | - static_assert(!std::is_reference_v<T>); |
104 | | - static_assert(std::is_rvalue_reference_v<U>); |
105 | | -}; |
106 | | - |
107 | | -template<class T, class U = T&&> |
108 | | -struct variant_nothrow_move_assignable : std::conjunction<std::is_nothrow_constructible<T, U>, std::is_nothrow_assignable<T&, U>> |
109 | | -{ |
110 | | - static_assert(!std::is_reference_v<T>); |
111 | | - static_assert(std::is_rvalue_reference_v<U>); |
112 | | - static_assert(variant_move_assignable<T, U>::value); |
113 | | -}; |
114 | | - |
115 | | -template<class T, class U> |
116 | | -struct variant_assignable : std::conjunction<std::is_constructible<T, U>, std::is_assignable<T&, U>> |
117 | | -{ |
118 | | - static_assert(!std::is_reference_v<T>); |
119 | | -}; |
120 | | - |
121 | | -template<class T, class U> |
122 | | -struct variant_nothrow_assignable : std::conjunction<std::is_nothrow_constructible<T, U>, std::is_nothrow_assignable<T&, U>> |
123 | | -{ |
124 | | - static_assert(!std::is_reference_v<T>); |
125 | | - static_assert(variant_assignable<T, U>::value); |
126 | | -}; |
127 | | - |
128 | 12 | } // iris::detail |
129 | 13 |
|
130 | 14 | #endif |
0 commit comments