CommonLibSSE (powerof3)
Loading...
Searching...
No Matches
BSTTuple.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace RE
6{
7 template <class T1, class T2>
8 struct BSTTuple
9 {
10 public:
11 using first_type = T1;
12 using second_type = T2;
13
14 // 1)
16 noexcept(std::is_nothrow_default_constructible_v<first_type>&&
17 std::is_nothrow_default_constructible_v<second_type>) //
18 requires(std::is_default_constructible_v<first_type> &&
19 std::is_default_constructible_v<second_type>)
20 :
21 first(),
22 second()
23 {}
24
25 // 2)
26 explicit(!std::is_convertible_v<const first_type&, first_type> ||
27 !std::is_convertible_v<const second_type&, second_type>) //
28 BSTTuple(const first_type& a_first, const second_type& a_second) //
29 noexcept(std::is_nothrow_copy_constructible_v<first_type>&&
30 std::is_nothrow_copy_constructible_v<second_type>) //
31 requires(std::is_copy_constructible_v<first_type> &&
32 std::is_copy_constructible_v<second_type>)
33 :
34 first(a_first),
35 second(a_second)
36 {}
37
38 // 3)
39 template <class U1, class U2>
40 explicit(!std::is_convertible_v<U1&&, first_type> ||
41 !std::is_convertible_v<U2&&, second_type>) //
42 BSTTuple(U1&& a_first, U2&& a_second) //
43 noexcept(std::is_nothrow_constructible_v<first_type, U1&&>&&
44 std::is_nothrow_constructible_v<second_type, U2&&>) //
45 requires(std::is_constructible_v<first_type, U1 &&> &&
46 std::is_constructible_v<second_type, U2 &&>)
47 :
48 first(std::forward<U1>(a_first)),
49 second(std::forward<U2>(a_second))
50 {}
51
52 // 4)
53 template <class U1, class U2>
54 explicit(!std::is_convertible_v<const U1&, first_type> ||
55 !std::is_convertible_v<const U2&, second_type>) //
56 BSTTuple(const BSTTuple<U1, U2>& a_rhs) //
57 noexcept(std::is_nothrow_constructible_v<first_type, const U1&>&&
58 std::is_nothrow_constructible_v<second_type, const U2&>) //
59 requires(std::is_constructible_v<first_type, const U1&> &&
60 std::is_constructible_v<second_type, const U2&>)
61 :
62 first(a_rhs.first),
63 second(a_rhs.second)
64 {}
65
66 // 5)
67 template <class U1, class U2>
68 explicit(!std::is_convertible_v<U1&&, first_type> ||
69 !std::is_convertible_v<U2&&, second_type>) //
70 BSTTuple(BSTTuple<U1, U2>&& a_rhs) //
71 noexcept(std::is_nothrow_constructible_v<first_type, U1&&>&&
72 std::is_nothrow_constructible_v<second_type, U2&&>) //
73 requires(std::is_constructible_v<first_type, U1 &&> &&
74 std::is_constructible_v<second_type, U2 &&>)
75 :
76 first(std::forward<U1>(a_rhs.first)),
77 second(std::forward<U2>(a_rhs.second))
78 {}
79
80 // 6)
81 template <
82 class... Args1,
83 class... Args2>
84 BSTTuple(std::piecewise_construct_t, std::tuple<Args1...> a_firstArgs, std::tuple<Args2...> a_secondArgs) :
85 BSTTuple(a_firstArgs, a_secondArgs, std::index_sequence_for<Args1...>(), std::index_sequence_for<Args2...>())
86 {}
87
88 private:
89 // 6) impl
90 template <
91 class Tuple1,
92 class Tuple2,
93 std::size_t... I1,
94 std::size_t... I2>
95 BSTTuple(Tuple1& a_firstArgs, Tuple2& a_secondArgs, std::index_sequence<I1...>, std::index_sequence<I2...>) :
96 first(std::get<I1>(std::move(a_firstArgs))...),
97 second(std::get<I2>(std::move(a_secondArgs))...)
98 {}
99
100 public:
101 // 7)
102 BSTTuple(const BSTTuple&) = default;
103
104 // 8)
105 BSTTuple(BSTTuple&&) = default;
106
107 ~BSTTuple() = default;
108
109 // 1)
110 BSTTuple& operator=(const BSTTuple& a_rhs) //
111 noexcept(std::is_nothrow_copy_assignable_v<first_type>&&
112 std::is_nothrow_copy_assignable_v<second_type>) //
113 requires(std::is_copy_assignable_v<first_type> &&
114 std::is_copy_assignable_v<second_type>)
115 {
116 if (this != std::addressof(a_rhs)) {
117 first = a_rhs.first;
118 second = a_rhs.second;
119 }
120 return *this;
121 }
122
123 // 2)
124 template <class U1, class U2>
126 noexcept(std::is_nothrow_assignable_v<first_type&, const U1&>&&
127 std::is_nothrow_assignable_v<second_type&, const U2&>) //
128 requires(std::is_assignable_v<first_type&, const U1&> &&
129 std::is_assignable_v<second_type&, const U2&>)
130 {
131 first = a_rhs.first;
132 second = a_rhs.second;
133 return *this;
134 }
135
136 // 3)
138 noexcept(std::is_nothrow_move_assignable_v<first_type>&&
139 std::is_nothrow_move_assignable_v<second_type>) //
140 requires(std::is_move_assignable_v<first_type> &&
141 std::is_move_assignable_v<second_type>)
142 {
143 if (this != std::addressof(a_rhs)) {
144 first = std::move(a_rhs.first);
145 second = std::move(a_rhs.second);
146 }
147 return *this;
148 }
149
150 // 4)
151 template <class U1, class U2>
153 noexcept(std::is_nothrow_assignable_v<first_type&, U1>&&
154 std::is_nothrow_assignable_v<second_type&, U2>) //
155 requires(std::is_assignable_v<first_type&, U1> &&
156 std::is_assignable_v<second_type&, U2>)
157 {
158 first = std::move(a_rhs.first);
159 second = std::move(a_rhs.second);
160 return *this;
161 }
162
164
165 void swap(BSTTuple& a_rhs) //
166 noexcept(std::is_nothrow_swappable_v<first_type>&&
167 std::is_nothrow_swappable_v<second_type>)
168 {
169 using std::swap;
170 if (this != std::addressof(a_rhs)) {
171 swap(first, a_rhs.first);
172 swap(second, a_rhs.second);
173 }
174 }
175
176 // members
179 };
180
181 template <class T1, class T2>
182 [[nodiscard]] auto make_pair(T1&& a_first, T2&& a_second)
183 {
184 using result_t =
185 BSTTuple<
186 std::decay_t<T1>,
187 std::decay_t<T2>>;
188 return result_t(std::forward<T1>(a_first), std::forward<T2>(a_second));
189 }
190
191 template <class T1, class T2>
192 [[nodiscard]] auto make_tuple(T1&& a_first, T2&& a_second)
193 {
194 using result_t =
195 BSTTuple<
196 std::decay_t<T1>,
197 std::decay_t<T2>>;
198 return result_t(std::forward<T1>(a_first), std::forward<T2>(a_second));
199 }
200
201 template <class T1, class T2>
202 [[nodiscard]] bool operator==(const BSTTuple<T1, T2>& a_lhs, const BSTTuple<T1, T2>& a_rhs)
203 {
204 return a_lhs.first == a_rhs.first && a_lhs.second == a_rhs.second;
205 }
206
207 template <class T1, class T2>
208 [[nodiscard]] bool operator<(const BSTTuple<T1, T2>& a_lhs, const BSTTuple<T1, T2>& a_rhs)
209 {
210 return a_lhs.first < a_rhs.first ? true :
211 a_rhs.first < a_lhs.first ? false :
212 a_lhs.second < a_rhs.second ? true :
213 false;
214 }
215
216 template <class T1, class T2>
217 void swap(BSTTuple<T1, T2>& a_lhs, BSTTuple<T1, T2>& a_rhs) //
218 noexcept(noexcept(a_lhs.swap(a_rhs))) //
219 requires(std::is_swappable_v<T1> &&
220 std::is_swappable_v<T2>)
221 {
222 a_lhs.swap(a_rhs);
223 }
224
225 template <class T1, class T2>
227}
Definition AbsorbEffect.h:6
auto make_pair(T1 &&a_first, T2 &&a_second)
Definition BSTTuple.h:182
constexpr bool operator==(const BSTSmartPointer< T1 > &a_lhs, const BSTSmartPointer< T2 > &a_rhs)
Definition BSTSmartPointer.h:241
void swap(BSTTuple< T1, T2 > &a_lhs, BSTTuple< T1, T2 > &a_rhs) noexcept(noexcept(a_lhs.swap(a_rhs)))
Definition BSTTuple.h:217
auto make_tuple(T1 &&a_first, T2 &&a_second)
Definition BSTTuple.h:192
bool operator<(const BSTTuple< T1, T2 > &a_lhs, const BSTTuple< T1, T2 > &a_rhs)
Definition BSTTuple.h:208
Definition EffectArchetypes.h:65
Definition BSTTuple.h:9
BSTTuple() noexcept(std::is_nothrow_default_constructible_v< first_type > &&std::is_nothrow_default_constructible_v< second_type >)
Definition BSTTuple.h:15
BSTTuple(std::piecewise_construct_t, std::tuple< Args1... > a_firstArgs, std::tuple< Args2... > a_secondArgs)
Definition BSTTuple.h:84
first_type first
Definition BSTTuple.h:177
second_type second
Definition BSTTuple.h:178
const second_type &a_second noexcept(std::is_nothrow_copy_constructible_v< first_type > &&std::is_nothrow_copy_constructible_v< second_type >)
Definition BSTTuple.h:29
~BSTTuple()=default
BSTTuple & operator=(BSTTuple &&a_rhs) noexcept(std::is_nothrow_move_assignable_v< first_type > &&std::is_nothrow_move_assignable_v< second_type >)
Definition BSTTuple.h:137
BSTTuple & operator=(const BSTTuple &a_rhs) noexcept(std::is_nothrow_copy_assignable_v< first_type > &&std::is_nothrow_copy_assignable_v< second_type >)
Definition BSTTuple.h:110
T2 second_type
Definition BSTTuple.h:12
BSTTuple & operator=(BSTTuple< U1, U2 > &&a_rhs) noexcept(std::is_nothrow_assignable_v< first_type &, U1 > &&std::is_nothrow_assignable_v< second_type &, U2 >)
Definition BSTTuple.h:152
void swap(BSTTuple &a_rhs) noexcept(std::is_nothrow_swappable_v< first_type > &&std::is_nothrow_swappable_v< second_type >)
Definition BSTTuple.h:165
T1 first_type
Definition BSTTuple.h:11
BSTTuple(BSTTuple &&)=default
BSTTuple & operator=(const BSTTuple< U1, U2 > &a_rhs) noexcept(std::is_nothrow_assignable_v< first_type &, const U1 & > &&std::is_nothrow_assignable_v< second_type &, const U2 & >)
Definition BSTTuple.h:125
BSTTuple(const BSTTuple &)=default