Commit 1dba5cd5 authored by Dominik Charousset's avatar Dominik Charousset

Add to_string and serialize to optional

parent 290c5214
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "caf/none.hpp" #include "caf/none.hpp"
#include "caf/unit.hpp" #include "caf/unit.hpp"
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/detail/safe_equal.hpp" #include "caf/detail/safe_equal.hpp"
...@@ -227,6 +228,36 @@ class optional<T&> { ...@@ -227,6 +228,36 @@ class optional<T&> {
T* m_value; T* m_value;
}; };
/// @relates optional
template <class T>
std::string to_string(const optional<T>& x) {
return x ? "!" + deep_to_string(*x) : "<none>";
}
/// @relates optional
template <class Processor, class T>
typename std::enable_if<Processor::is_saving::value>::type
serialize(Processor& sink, optional<T>& x, const unsigned int) {
uint8_t flag = x ? 1 : 0;
sink & flag;
if (flag)
sink & *x;
}
/// @relates optional
template <class Processor, class T>
typename std::enable_if<Processor::is_loading::value>::type
serialize(Processor& source, optional<T>& x, const unsigned int) {
uint8_t flag;
source & flag;
if (flag) {
T value;
source & value;
x = std::move(value);
}
x = none;
}
/// @relates optional /// @relates optional
template <class T, class U> template <class T, class U>
bool operator==(const optional<T>& lhs, const optional<U>& rhs) { bool operator==(const optional<T>& lhs, const optional<U>& rhs) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment