Skip to content

Commit

Permalink
Making future serialization symmetric even for non-default-constructi…
Browse files Browse the repository at this point in the history
…ble value types
  • Loading branch information
hkaiser committed Aug 19, 2017
1 parent e4c1c0a commit 7d28e21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 21 additions & 3 deletions hpx/lcos/future.hpp
Expand Up @@ -106,8 +106,9 @@ namespace hpx { namespace lcos { namespace detail
ar >> state;
if (state == future_state::has_value)
{
serialize_future_load(ar, f,
typename std::is_default_constructible<value_type>::type());
serialize_future_load(
ar, f, std::is_default_constructible<value_type>());

} else if (state == future_state::has_exception) {
std::exception_ptr exception;
ar >> exception;
Expand Down Expand Up @@ -158,6 +159,19 @@ namespace hpx { namespace lcos { namespace detail
}
}

template <typename Archive, typename T>
void serialize_future_save(Archive& ar, T const& val, std::false_type)
{
serialization::detail::save_construct_data(ar, &val, 0);
ar << val;
}

template <typename Archive, typename T>
void serialize_future_save(Archive& ar, T const& val, std::true_type)
{
ar << val;
}

template <typename Archive, typename Future>
typename std::enable_if<
!std::is_void<typename hpx::traits::future_traits<Future>::type>::value
Expand Down Expand Up @@ -192,7 +206,11 @@ namespace hpx { namespace lcos { namespace detail
value_type const & value =
*hpx::traits::future_access<Future>::
get_shared_state(f)->get_result();
ar << state << value; //-V128
ar << state;

serialize_future_save(
ar, value, std::is_default_constructible<value_type>());

} else if (f.has_exception()) {
state = future_state::has_exception;
std::exception_ptr exception = f.get_exception_ptr();
Expand Down
Expand Up @@ -85,8 +85,7 @@ namespace hpx { namespace serialization { namespace detail
public:
static T* create(input_archive& ar)
{
return create(
ar, typename std::is_default_constructible<T>::type());
return create(ar, std::is_default_constructible<T>());
}

// is default-constructible
Expand Down

0 comments on commit 7d28e21

Please sign in to comment.