mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 16:56:17 +08:00
Use std::launder where appropriate (#181)
This commit is contained in:
@@ -57,14 +57,15 @@ class Tuple {
|
||||
template <int _index>
|
||||
auto& get() {
|
||||
using Type = internal::nth_element_t<_index, Types...>;
|
||||
return *(reinterpret_cast<Type*>(data_.data() + pos<_index>()));
|
||||
return *std::launder(reinterpret_cast<Type*>(data_.data() + pos<_index>()));
|
||||
}
|
||||
|
||||
/// Gets an element by index.
|
||||
template <int _index>
|
||||
const auto& get() const {
|
||||
using Type = internal::nth_element_t<_index, Types...>;
|
||||
return *(reinterpret_cast<const Type*>(data_.data() + pos<_index>()));
|
||||
return *std::launder(
|
||||
reinterpret_cast<const Type*>(data_.data() + pos<_index>()));
|
||||
}
|
||||
|
||||
/// Assigns the underlying object.
|
||||
@@ -131,8 +132,7 @@ class Tuple {
|
||||
const auto copy_one = [this]<int _i>(const auto& _other,
|
||||
std::integral_constant<int, _i>) {
|
||||
using Type = internal::nth_element_t<_i, Types...>;
|
||||
new (reinterpret_cast<Type*>(data_.data() + pos<_i>()))
|
||||
Type(_other.template get<_i>());
|
||||
new (data_.data() + pos<_i>()) Type(_other.template get<_i>());
|
||||
};
|
||||
(copy_one(_other, std::integral_constant<int, _is>{}), ...);
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class Tuple {
|
||||
const auto copy_one = [this]<int _i>(const auto& _t,
|
||||
std::integral_constant<int, _i>) {
|
||||
using Type = internal::nth_element_t<_i, Types...>;
|
||||
new (reinterpret_cast<Type*>(data_.data() + pos<_i>())) Type(_t);
|
||||
new (data_.data() + pos<_i>()) Type(_t);
|
||||
};
|
||||
(copy_one(_types, std::integral_constant<int, _is>{}), ...);
|
||||
}
|
||||
@@ -165,8 +165,7 @@ class Tuple {
|
||||
const auto move_one = [this]<int _i>(auto&& _other,
|
||||
std::integral_constant<int, _i>) {
|
||||
using Type = internal::nth_element_t<_i, Types...>;
|
||||
new (reinterpret_cast<Type*>(data_.data() + pos<_i>()))
|
||||
Type(std::move(_other.template get<_i>()));
|
||||
new (data_.data() + pos<_i>()) Type(std::move(_other.template get<_i>()));
|
||||
};
|
||||
(move_one(_other, std::integral_constant<int, _is>{}), ...);
|
||||
}
|
||||
@@ -176,8 +175,7 @@ class Tuple {
|
||||
const auto move_one = [this]<int _i>(auto&& _t,
|
||||
std::integral_constant<int, _i>) {
|
||||
using Type = internal::nth_element_t<_i, Types...>;
|
||||
new (reinterpret_cast<Type*>(data_.data() + pos<_i>()))
|
||||
Type(std::move(_t));
|
||||
new (data_.data() + pos<_i>()) Type(std::move(_t));
|
||||
};
|
||||
(move_one(std::move(_types), std::integral_constant<int, _is>{}), ...);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user