Skip to content

Commit c97d3b5

Browse files
author
Marc Kramer
committed
Merge branch 'use_alignas' of https://github.com/gre-42/cereal into use_alignas
2 parents a6c6c39 + 393efbc commit c97d3b5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

include/cereal/types/memory.hpp

Lines changed: 8 additions & 2 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
@@ -380,7 +383,10 @@ namespace cereal
380383
using NonConstT = typename std::remove_const<T>::type;
381384
// Storage type for the pointer - since we can't default construct this type,
382385
// we'll allocate it using std::aligned_storage
383-
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+
};
384390

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

0 commit comments

Comments
 (0)