Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #423

Merged
merged 18 commits into from
Nov 20, 2017
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace std::decay with std::remove_const
  • Loading branch information
WSoptics committed Aug 17, 2017
commit c3eda13e9eb6c6fa53d8820b6b4c55c0f21ff55e
17 changes: 9 additions & 8 deletions include/cereal/types/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ namespace cereal

// Allocate our storage, which we will treat as
// uninitialized until initialized with placement new
std::shared_ptr<typename std::decay<T>::type> ptr(reinterpret_cast<T *>(new ST()),
std::shared_ptr<typename std::remove_const<T>::type> ptr(reinterpret_cast<T *>(new ST()),
[=]( T * t )
{
if( *valid )
Expand All @@ -315,7 +315,7 @@ namespace cereal
wrapper.ptr = std::move(ptr);
}
else
wrapper.ptr = std::static_pointer_cast<typename std::decay<T>::type>(ar.getSharedPointer(id));
wrapper.ptr = std::static_pointer_cast<typename std::remove_const<T>::type>(ar.getSharedPointer(id));
}

//! Loading std::shared_ptr, case when no user load and construct (wrapper implementation)
Expand All @@ -330,7 +330,8 @@ namespace cereal

if( id & detail::msb_32bit )
{
std::shared_ptr<typename std::decay<T>::type> ptr( detail::Construct<typename std::decay<T>::type, Archive>::load_andor_construct() );
using NonConstT = typename std::remove_const<T>::type;
std::shared_ptr<NonConstT> ptr( detail::Construct<NonConstT, Archive>::load_andor_construct() );
ar.registerSharedPointer( id, ptr );
ar( CEREAL_NVP_("data", *ptr) );
wrapper.ptr = std::move(ptr);
Expand Down Expand Up @@ -372,17 +373,17 @@ namespace cereal

if( isValid )
{
using DecayT = typename std::decay<T>::type;
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 ST = typename std::aligned_storage<sizeof(DecayT), CEREAL_ALIGNOF(DecayT)>::type;
using ST = typename std::aligned_storage<sizeof(NonConstT), CEREAL_ALIGNOF(NonConstT)>::type;

// Allocate storage - note the ST type so that deleter is correct if
// an exception is thrown before we are initialized
std::unique_ptr<ST> stPtr( new ST() );

// Use wrapper to enter into "data" nvp of ptr_wrapper
memory_detail::LoadAndConstructLoadWrapper<Archive, DecayT> loadWrapper( reinterpret_cast<DecayT *>( stPtr.get() ) );
memory_detail::LoadAndConstructLoadWrapper<Archive, NonConstT> loadWrapper( reinterpret_cast<NonConstT *>( stPtr.get() ) );

// Initialize storage
ar( CEREAL_NVP_("data", loadWrapper) );
Expand All @@ -405,8 +406,8 @@ namespace cereal

if( isValid )
{
using DecayT = typename std::decay<T>::type;
std::unique_ptr<DecayT, D> ptr( detail::Construct<DecayT, Archive>::load_andor_construct() );
using NonConstT = typename std::remove_const<T>::type;
std::unique_ptr<NonConstT, D> ptr( detail::Construct<NonConstT, Archive>::load_andor_construct() );
ar( CEREAL_NVP_( "data", *ptr ) );
wrapper.ptr = std::move(ptr);
}
Expand Down