Skip to content

Commit

Permalink
Adding hpx::util::optional as a first step to replace experimental::o…
Browse files Browse the repository at this point in the history
…ptional
  • Loading branch information
hkaiser committed Nov 11, 2017
1 parent 5fcd512 commit f81d7d2
Show file tree
Hide file tree
Showing 5 changed files with 686 additions and 1 deletion.
1 change: 1 addition & 0 deletions hpx/include/serialization.hpp
Expand Up @@ -19,6 +19,7 @@
#include <hpx/runtime/serialization/list.hpp>
#include <hpx/runtime/serialization/map.hpp>
#include <hpx/runtime/serialization/multi_array.hpp>
#include <hpx/runtime/serialization/optional.hpp>
#include <hpx/runtime/serialization/partitioned_vector.hpp>
#include <hpx/runtime/serialization/serialize_buffer.hpp>
#include <hpx/runtime/serialization/set.hpp>
Expand Down
46 changes: 46 additions & 0 deletions hpx/runtime/serialization/optional.hpp
@@ -0,0 +1,46 @@
// Copyright (c) 2017 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(HPX_OPTIONAL_SERIALIZATION_HPP)
#define HPX_OPTIONAL_SERIALIZATION_HPP

#include <hpx/config.hpp>
#include <hpx/util/optional.hpp>
#include <hpx/runtime/serialization/serialize.hpp>

namespace hpx { namespace serialization
{
template <typename T>
void save(output_archive& ar, hpx::util::optional<T> const& o, unsigned)
{
bool const valid = bool(o);
ar << valid;
if (valid)
{
ar << *o;
}
}

template <typename T>
void load(input_archive& ar, hpx::util::optional<T>& o, unsigned)
{
bool valid = false;
ar >> valid;
if (!valid)
{
o.reset();
return;
}

T value;
ar >> value;
o.emplace(std::move(value));
}

HPX_SERIALIZATION_SPLIT_FREE_TEMPLATE(
(template <typename T>), (hpx::util::optional<T>));
}}

#endif // HPX_OPTIONAL_SERIALIZATION_HPP

0 comments on commit f81d7d2

Please sign in to comment.