Skip to content

Commit

Permalink
Merge branch 'use_alignas' of https://github.com/gre-42/cereal into u…
Browse files Browse the repository at this point in the history
…se_alignas
  • Loading branch information
Marc Kramer committed Aug 17, 2024
2 parents a6c6c39 + 393efbc commit c97d3b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/cereal/types/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ namespace cereal
// typedefs for parent type and storage type
using BaseType = typename ::cereal::traits::get_shared_from_this_base<T>::type;
using ParentType = std::enable_shared_from_this<BaseType>;
using StorageType = typename std::aligned_storage<sizeof(ParentType), CEREAL_ALIGNOF(ParentType)>::type;
class alignas(ParentType) StorageType {
private:
std::byte data[sizeof(ParentType)];
};

public:
//! Saves the state of some type inheriting from enable_shared_from_this
Expand Down Expand Up @@ -380,7 +383,10 @@ namespace cereal
using NonConstT = typename std::remove_const<T>::type;
// Storage type for the pointer - since we can't default construct this type,
// we'll allocate it using std::aligned_storage
using AlignedStorage = typename std::aligned_storage<sizeof(NonConstT), CEREAL_ALIGNOF(NonConstT)>::type;
class alignas(NonConstT) AlignedStorage {
private:
std::byte data[sizeof(NonConstT)];
};

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

0 comments on commit c97d3b5

Please sign in to comment.