Skip to content

Commit 4709bf7

Browse files
Marc Kramergre-42
authored andcommitted
Use alignas instead of std::aligned_storage
1 parent a56bad8 commit 4709bf7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

include/cereal/types/memory.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ namespace cereal
134134
// typedefs for parent type and storage type
135135
using BaseType = typename ::cereal::traits::get_shared_from_this_base<T>::type;
136136
using ParentType = std::enable_shared_from_this<BaseType>;
137-
using StorageType = typename std::aligned_storage<sizeof(ParentType), CEREAL_ALIGNOF(ParentType)>::type;
137+
class alignas(ParentType) StorageType {
138+
private:
139+
std::byte data[sizeof(ParentType)];
140+
};
138141

139142
public:
140143
//! Saves the state of some type inheriting from enable_shared_from_this
@@ -286,7 +289,10 @@ namespace cereal
286289
{
287290
// Storage type for the pointer - since we can't default construct this type,
288291
// we'll allocate it using std::aligned_storage and use a custom deleter
289-
using AlignedStorage = typename std::aligned_storage<sizeof(T), CEREAL_ALIGNOF(T)>::type;
292+
class alignas(T) AlignedStorage {
293+
private:
294+
std::byte data[sizeof(T)];
295+
};
290296

291297
// Valid flag - set to true once construction finishes
292298
// This prevents us from calling the destructor on
@@ -377,7 +383,10 @@ namespace cereal
377383
using NonConstT = typename std::remove_const<T>::type;
378384
// Storage type for the pointer - since we can't default construct this type,
379385
// we'll allocate it using std::aligned_storage
380-
using AlignedStorage = typename std::aligned_storage<sizeof(NonConstT), CEREAL_ALIGNOF(NonConstT)>::type;
386+
class alignas(NonConstT) AlignedStorage {
387+
private:
388+
std::byte data[sizeof(NonConstT)];
389+
};
381390

382391
// Allocate storage - note the AlignedStorage type so that deleter is correct if
383392
// an exception is thrown before we are initialized

0 commit comments

Comments
 (0)