mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Replace C++23-deprecated aligned_storage_t
This commit is contained in:
parent
d9b0a38f81
commit
a733b58cd2
@ -20,9 +20,7 @@ namespace Catch {
|
|||||||
template <typename T, bool Destruct>
|
template <typename T, bool Destruct>
|
||||||
struct ObjectStorage
|
struct ObjectStorage
|
||||||
{
|
{
|
||||||
using TStorage = std::aligned_storage_t<sizeof(T), std::alignment_of<T>::value>;
|
ObjectStorage() = default;
|
||||||
|
|
||||||
ObjectStorage() : data() {}
|
|
||||||
|
|
||||||
ObjectStorage(const ObjectStorage& other)
|
ObjectStorage(const ObjectStorage& other)
|
||||||
{
|
{
|
||||||
@ -31,7 +29,7 @@ namespace Catch {
|
|||||||
|
|
||||||
ObjectStorage(ObjectStorage&& other)
|
ObjectStorage(ObjectStorage&& other)
|
||||||
{
|
{
|
||||||
new(&data) T(CATCH_MOVE(other.stored_object()));
|
new(data) T(CATCH_MOVE(other.stored_object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
~ObjectStorage() { destruct_on_exit<T>(); }
|
~ObjectStorage() { destruct_on_exit<T>(); }
|
||||||
@ -39,7 +37,7 @@ namespace Catch {
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void construct(Args&&... args)
|
void construct(Args&&... args)
|
||||||
{
|
{
|
||||||
new (&data) T(CATCH_FORWARD(args)...);
|
new (data) T(CATCH_FORWARD(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool AllowManualDestruction = !Destruct>
|
template <bool AllowManualDestruction = !Destruct>
|
||||||
@ -57,15 +55,15 @@ namespace Catch {
|
|||||||
void destruct_on_exit(std::enable_if_t<!Destruct, U>* = nullptr) { }
|
void destruct_on_exit(std::enable_if_t<!Destruct, U>* = nullptr) { }
|
||||||
|
|
||||||
T& stored_object() {
|
T& stored_object() {
|
||||||
return *static_cast<T*>(static_cast<void*>(&data));
|
return *static_cast<T*>(static_cast<void*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
T const& stored_object() const {
|
T const& stored_object() const {
|
||||||
return *static_cast<T*>(static_cast<void*>(&data));
|
return *static_cast<T*>(static_cast<void*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TStorage data;
|
alignas( T ) unsigned char data[sizeof( T )]{};
|
||||||
};
|
};
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user