Skip to content

Commit

Permalink
GH-737 Allow unpack of std::shared_ptr<const T>
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Sep 11, 2024
1 parent 78cf07f commit b401100
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 5 additions & 6 deletions libraries/libfc/include/fc/io/raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ namespace fc {
inline void unpack( Stream& s, std::shared_ptr<T>& v)
{ try {
bool b; fc::raw::unpack( s, b );
if( b ) { v = std::make_shared<T>(); fc::raw::unpack( s, *v ); }
if( b ) {
v = std::make_shared<T>();
// want to be able to unpack std::shared_ptr<const T>, note we already overwrote with a new one above
fc::raw::unpack( s, const_cast<std::remove_const_t<T>&>(*v) );
}
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<T>", ("type",fc::get_typename<T>::name()) ) }

template<typename Stream> inline void pack( Stream& s, const signed_int& v ) {
Expand Down Expand Up @@ -245,11 +249,6 @@ namespace fc {
vi.value = static_cast<uint32_t>(v);
}

template<typename Stream, typename T> inline void unpack( Stream& s, const T& vi )
{
static_assert(not std::is_same_v<const T, const T>, "can't unpack const type");
}

template<typename Stream> inline void pack( Stream& s, const char* v ) {
size_t sz = std::strlen(v);
FC_ASSERT( sz <= MAX_SIZE_OF_BYTE_ARRAYS );
Expand Down
1 change: 0 additions & 1 deletion libraries/libfc/include/fc/io/raw_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ namespace fc {


template<typename Stream, typename T> void unpack( Stream& s, std::optional<T>& v );
template<typename Stream, typename T> void unpack( Stream& s, const T& v );
template<typename Stream, typename T> void pack( Stream& s, const std::optional<T>& v );
template<typename Stream, typename T> void pack( Stream& s, const safe<T>& v );
template<typename Stream, typename T> void unpack( Stream& s, fc::safe<T>& v );
Expand Down

0 comments on commit b401100

Please sign in to comment.