3
3
4
4
#include < algorithm>
5
5
#include < array>
6
+ #include < bit>
6
7
#include < cstdint>
7
8
#include < limits>
9
+ #include < memory>
8
10
#include < optional>
9
11
#include < stdexcept>
10
12
#include < tuple>
@@ -55,17 +57,16 @@ class Tuple {
55
57
56
58
// / Gets an element by index.
57
59
template <int _index>
58
- auto & get () {
60
+ constexpr auto & get () {
59
61
using Type = internal::nth_element_t <_index, Types...>;
60
- return *std::launder ( reinterpret_cast <Type*>(data_.data () + pos<_index>() ));
62
+ return *std::bit_cast <Type*>(data_.data () + pos<_index>());
61
63
}
62
64
63
65
// / Gets an element by index.
64
66
template <int _index>
65
- const auto & get () const {
67
+ constexpr const auto & get () const {
66
68
using Type = internal::nth_element_t <_index, Types...>;
67
- return *std::launder (
68
- reinterpret_cast <const Type*>(data_.data () + pos<_index>()));
69
+ return *std::bit_cast<const Type*>(data_.data () + pos<_index>());
69
70
}
70
71
71
72
// / Assigns the underlying object.
@@ -132,7 +133,8 @@ class Tuple {
132
133
const auto copy_one = [this ]<int _i>(const auto & _other,
133
134
std::integral_constant<int , _i>) {
134
135
using Type = internal::nth_element_t <_i, Types...>;
135
- new (data_.data () + pos<_i>()) Type (_other.template get <_i>());
136
+ ::new (static_cast <void *>(data_.data () + pos<_i>()))
137
+ Type (_other.template get <_i>());
136
138
};
137
139
(copy_one (_other, std::integral_constant<int , _is>{}), ...);
138
140
}
@@ -143,7 +145,7 @@ class Tuple {
143
145
const auto copy_one = [this ]<int _i>(const auto & _t,
144
146
std::integral_constant<int , _i>) {
145
147
using Type = internal::nth_element_t <_i, Types...>;
146
- new (data_.data () + pos<_i>()) Type (_t);
148
+ :: new (static_cast < void *>( data_.data () + pos<_i>() )) Type (_t);
147
149
};
148
150
(copy_one (_types, std::integral_constant<int , _is>{}), ...);
149
151
}
@@ -165,7 +167,8 @@ class Tuple {
165
167
const auto move_one = [this ]<int _i>(auto && _other,
166
168
std::integral_constant<int , _i>) {
167
169
using Type = internal::nth_element_t <_i, Types...>;
168
- new (data_.data () + pos<_i>()) Type (std::move (_other.template get <_i>()));
170
+ ::new (static_cast <void *>(data_.data () + pos<_i>()))
171
+ Type (std::move (_other.template get <_i>()));
169
172
};
170
173
(move_one (_other, std::integral_constant<int , _is>{}), ...);
171
174
}
@@ -175,7 +178,7 @@ class Tuple {
175
178
const auto move_one = [this ]<int _i>(auto && _t,
176
179
std::integral_constant<int , _i>) {
177
180
using Type = internal::nth_element_t <_i, Types...>;
178
- new (data_.data () + pos<_i>()) Type (std::move (_t));
181
+ :: new (static_cast < void *>( data_.data () + pos<_i>() )) Type (std::move (_t));
179
182
};
180
183
(move_one (std::move (_types), std::integral_constant<int , _is>{}), ...);
181
184
}
@@ -192,25 +195,25 @@ class Tuple {
192
195
193
196
// / Gets an element by index.
194
197
template <int _index, class ... Types>
195
- auto & get (rfl::Tuple<Types...>& _tup) {
198
+ constexpr auto & get (rfl::Tuple<Types...>& _tup) {
196
199
return _tup.template get <_index>();
197
200
}
198
201
199
202
// / Gets an element by index.
200
203
template <int _index, class ... Types>
201
- const auto & get (const rfl::Tuple<Types...>& _tup) {
204
+ constexpr const auto & get (const rfl::Tuple<Types...>& _tup) {
202
205
return _tup.template get <_index>();
203
206
}
204
207
205
208
// / Gets an element by index.
206
209
template <int _index, class ... Types>
207
- auto & get (std::tuple<Types...>& _tup) {
210
+ constexpr auto & get (std::tuple<Types...>& _tup) {
208
211
return std::get<_index>(_tup);
209
212
}
210
213
211
214
// / Gets an element by index.
212
215
template <int _index, class ... Types>
213
- const auto & get (const std::tuple<Types...>& _tup) {
216
+ constexpr const auto & get (const std::tuple<Types...>& _tup) {
214
217
return std::get<_index>(_tup);
215
218
}
216
219
@@ -259,13 +262,13 @@ namespace std {
259
262
260
263
// / Gets an element by index.
261
264
template <int _index, class ... Types>
262
- auto & get (rfl::Tuple<Types...>& _tup) {
265
+ constexpr auto & get (rfl::Tuple<Types...>& _tup) {
263
266
return _tup.template get <_index>();
264
267
}
265
268
266
269
// / Gets an element by index.
267
270
template <int _index, class ... Types>
268
- const auto & get (const rfl::Tuple<Types...>& _tup) {
271
+ constexpr const auto & get (const rfl::Tuple<Types...>& _tup) {
269
272
return _tup.template get <_index>();
270
273
}
271
274
0 commit comments