Commit d192794a authored by Dominik Charousset's avatar Dominik Charousset

Merge pull request #1290

parents 1c25c912 9c66965e
...@@ -195,12 +195,12 @@ string trim(std::string s) { ...@@ -195,12 +195,12 @@ string trim(std::string s) {
} }
// tries to convert `str` to an int // tries to convert `str` to an int
optional<int> toint(const string& str) { std::optional<int> toint(const string& str) {
char* end; char* end;
auto result = static_cast<int>(strtol(str.c_str(), &end, 10)); auto result = static_cast<int>(strtol(str.c_str(), &end, 10));
if (end == str.c_str() + str.size()) if (end == str.c_str() + str.size())
return result; return result;
return none; return std::nullopt;
} }
// --(rst-config-begin)-- // --(rst-config-begin)--
......
...@@ -81,12 +81,12 @@ void client_repl(function_view<calculator> f) { ...@@ -81,12 +81,12 @@ void client_repl(function_view<calculator> f) {
usage(); usage();
continue; continue;
} }
auto to_int32_t = [](const string& str) -> optional<int32_t> { auto to_int32_t = [](const string& str) -> std::optional<int32_t> {
char* end = nullptr; char* end = nullptr;
auto res = strtol(str.c_str(), &end, 10); auto res = strtol(str.c_str(), &end, 10);
if (end == str.c_str() + str.size()) if (end == str.c_str() + str.size())
return static_cast<int32_t>(res); return static_cast<int32_t>(res);
return none; return std::nullopt;
}; };
auto x = to_int32_t(words[0]); auto x = to_int32_t(words[0]);
auto y = to_int32_t(words[2]); auto y = to_int32_t(words[2]);
......
...@@ -85,8 +85,8 @@ std::string get_rtti_from_mpi() { ...@@ -85,8 +85,8 @@ std::string get_rtti_from_mpi() {
namespace caf { namespace caf {
/// Actor environment including scheduler, registry, and optional components /// Actor environment including scheduler, registry, and optional
/// such as a middleman. /// components such as a middleman.
class CAF_CORE_EXPORT actor_system { class CAF_CORE_EXPORT actor_system {
public: public:
friend class logger; friend class logger;
...@@ -146,7 +146,8 @@ public: ...@@ -146,7 +146,8 @@ public:
using module_array = std::array<module_ptr, module::num_ids>; using module_array = std::array<module_ptr, module::num_ids>;
/// An (optional) component of the actor system with networking capabilities. /// An (optional) component of the actor system with networking
/// capabilities.
class CAF_CORE_EXPORT networking_module : public module { class CAF_CORE_EXPORT networking_module : public module {
public: public:
~networking_module() override; ~networking_module() override;
...@@ -659,7 +660,7 @@ private: ...@@ -659,7 +660,7 @@ private:
expected<strong_actor_ptr> expected<strong_actor_ptr>
dyn_spawn_impl(const std::string& name, message& args, execution_unit* ctx, dyn_spawn_impl(const std::string& name, message& args, execution_unit* ctx,
bool check_interface, optional<const mpi&> expected_ifs); bool check_interface, const mpi* expected_ifs);
/// Sets the internal actor for dynamic spawn operations. /// Sets the internal actor for dynamic spawn operations.
void spawn_serv(strong_actor_ptr x) { void spawn_serv(strong_actor_ptr x) {
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include "caf/message_priority.hpp" #include "caf/message_priority.hpp"
#include "caf/mtl.hpp" #include "caf/mtl.hpp"
#include "caf/node_id.hpp" #include "caf/node_id.hpp"
#include "caf/optional.hpp"
#include "caf/others.hpp" #include "caf/others.hpp"
#include "caf/proxy_registry.hpp" #include "caf/proxy_registry.hpp"
#include "caf/raise_error.hpp" #include "caf/raise_error.hpp"
......
...@@ -86,8 +86,8 @@ public: ...@@ -86,8 +86,8 @@ public:
} }
/// Runs this handler and returns its (optional) result. /// Runs this handler and returns its (optional) result.
optional<message> operator()(message& xs) { std::optional<message> operator()(message& xs) {
return impl_ ? impl_->invoke(xs) : none; return impl_ ? impl_->invoke(xs) : std::nullopt;
} }
/// Runs this handler with callback. /// Runs this handler with callback.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include "caf/detail/core_export.hpp" #include "caf/detail/core_export.hpp"
...@@ -97,7 +98,7 @@ public: ...@@ -97,7 +98,7 @@ public:
/// @private /// @private
// TODO: remove with CAF 0.17 // TODO: remove with CAF 0.17
optional<config_value> get() const; std::optional<config_value> get() const;
private: private:
string_view buf_slice(size_t from, size_t to) const noexcept; string_view buf_slice(size_t from, size_t to) const noexcept;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <iosfwd> #include <iosfwd>
#include <iterator> #include <iterator>
#include <map> #include <map>
#include <optional>
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
...@@ -28,7 +29,6 @@ ...@@ -28,7 +29,6 @@
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/inspector_access.hpp" #include "caf/inspector_access.hpp"
#include "caf/inspector_access_type.hpp" #include "caf/inspector_access_type.hpp"
#include "caf/optional.hpp"
#include "caf/raise_error.hpp" #include "caf/raise_error.hpp"
#include "caf/string_algorithms.hpp" #include "caf/string_algorithms.hpp"
#include "caf/string_view.hpp" #include "caf/string_view.hpp"
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
/// Tries to parse a config value (list) from `str` and to convert it to an /// Tries to parse a config value (list) from `str` and to convert it to an
/// allowed input message type for `Handle`. /// allowed input message type for `Handle`.
template <class Handle> template <class Handle>
static optional<message> parse_msg(string_view str, const Handle&) { static std::optional<message> parse_msg(string_view str, const Handle&) {
auto allowed = Handle::allowed_inputs(); auto allowed = Handle::allowed_inputs();
return parse_msg_impl(str, allowed); return parse_msg_impl(str, allowed);
} }
...@@ -264,7 +264,7 @@ private: ...@@ -264,7 +264,7 @@ private:
static const char* type_name_at_index(size_t index) noexcept; static const char* type_name_at_index(size_t index) noexcept;
static optional<message> static std::optional<message>
parse_msg_impl(string_view str, span<const type_id_list> allowed_types); parse_msg_impl(string_view str, span<const type_id_list> allowed_types);
// -- auto conversion of related types --------------------------------------- // -- auto conversion of related types ---------------------------------------
...@@ -561,7 +561,7 @@ auto get_or(const config_value& x, Fallback&& fallback) { ...@@ -561,7 +561,7 @@ auto get_or(const config_value& x, Fallback&& fallback) {
// -- SumType-like access ------------------------------------------------------ // -- SumType-like access ------------------------------------------------------
template <class T> template <class T>
[[deprecated("use get_as or get_or instead")]] optional<T> [[deprecated("use get_as or get_or instead")]] std::optional<T>
legacy_get_if(const config_value* x) { legacy_get_if(const config_value* x) {
if (auto val = get_as<T>(*x)) if (auto val = get_as<T>(*x))
return {std::move(*val)}; return {std::move(*val)};
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#pragma once #pragma once
#include <optional>
#include <utility> #include <utility>
#include "caf/detail/message_data.hpp" #include "caf/detail/message_data.hpp"
...@@ -27,8 +28,8 @@ public: ...@@ -27,8 +28,8 @@ public:
const_typed_message_view(const const_typed_message_view&) noexcept = default; const_typed_message_view(const const_typed_message_view&) noexcept = default;
const_typed_message_view& operator=(const const_typed_message_view&) noexcept const_typed_message_view&
= default; operator=(const const_typed_message_view&) noexcept = default;
const detail::message_data* operator->() const noexcept { const detail::message_data* operator->() const noexcept {
return ptr_; return ptr_;
...@@ -67,10 +68,10 @@ auto make_const_typed_message_view(const message& msg) { ...@@ -67,10 +68,10 @@ auto make_const_typed_message_view(const message& msg) {
} }
template <class... Ts> template <class... Ts>
optional<std::tuple<Ts...>> to_tuple(const message& msg) { std::optional<std::tuple<Ts...>> to_tuple(const message& msg) {
if (auto view = make_const_typed_message_view<Ts...>(msg)) if (auto view = make_const_typed_message_view<Ts...>(msg))
return to_tuple(view); return to_tuple(view);
return none; return std::nullopt;
} }
} // namespace caf } // namespace caf
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
#include "caf/byte_buffer.hpp" #include "caf/byte_buffer.hpp"
#include "caf/byte_span.hpp" #include "caf/byte_span.hpp"
#include "caf/detail/core_export.hpp" #include "caf/detail/core_export.hpp"
#include "caf/optional.hpp"
#include "caf/span.hpp" #include "caf/span.hpp"
#include "caf/string_view.hpp" #include "caf/string_view.hpp"
#include <optional>
#include <string> #include <string>
namespace caf::detail { namespace caf::detail {
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
static bool decode(const_byte_span bytes, byte_buffer& out); static bool decode(const_byte_span bytes, byte_buffer& out);
static optional<std::string> decode(string_view in) { static std::optional<std::string> decode(string_view in) {
std::string result; std::string result;
if (decode(in, result)) if (decode(in, result))
return {std::move(result)}; return {std::move(result)};
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
return {}; return {};
} }
static optional<std::string> decode(const_byte_span in) { static std::optional<std::string> decode(const_byte_span in) {
std::string result; std::string result;
if (decode(in, result)) if (decode(in, result))
return {std::move(result)}; return {std::move(result)};
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#pragma once #pragma once
#include <optional>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
...@@ -19,7 +20,6 @@ ...@@ -19,7 +20,6 @@
#include "caf/make_counted.hpp" #include "caf/make_counted.hpp"
#include "caf/message.hpp" #include "caf/message.hpp"
#include "caf/none.hpp" #include "caf/none.hpp"
#include "caf/optional.hpp"
#include "caf/ref_counted.hpp" #include "caf/ref_counted.hpp"
#include "caf/response_promise.hpp" #include "caf/response_promise.hpp"
#include "caf/skip.hpp" #include "caf/skip.hpp"
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
virtual bool invoke(detail::invoke_result_visitor& f, message& xs) = 0; virtual bool invoke(detail::invoke_result_visitor& f, message& xs) = 0;
optional<message> invoke(message&); std::optional<message> invoke(message&);
virtual void handle_timeout(); virtual void handle_timeout();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <optional>
#include <type_traits> #include <type_traits>
#include "caf/config.hpp" #include "caf/config.hpp"
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#include "caf/detail/parser/is_digit.hpp" #include "caf/detail/parser/is_digit.hpp"
#include "caf/detail/parser/sub_ascii.hpp" #include "caf/detail/parser/sub_ascii.hpp"
#include "caf/detail/scope_guard.hpp" #include "caf/detail/scope_guard.hpp"
#include "caf/optional.hpp"
#include "caf/pec.hpp" #include "caf/pec.hpp"
CAF_PUSH_UNUSED_LABEL_WARNING CAF_PUSH_UNUSED_LABEL_WARNING
...@@ -30,7 +30,7 @@ namespace caf::detail::parser { ...@@ -30,7 +30,7 @@ namespace caf::detail::parser {
/// the pre-decimal value. /// the pre-decimal value.
template <class State, class Consumer, class ValueType> template <class State, class Consumer, class ValueType>
void read_floating_point(State& ps, Consumer&& consumer, void read_floating_point(State& ps, Consumer&& consumer,
optional<ValueType> start_value, std::optional<ValueType> start_value,
bool negative = false) { bool negative = false) {
// Any exponent larger than 511 always overflows. // Any exponent larger than 511 always overflows.
static constexpr int max_double_exponent = 511; static constexpr int max_double_exponent = 511;
...@@ -38,7 +38,7 @@ void read_floating_point(State& ps, Consumer&& consumer, ...@@ -38,7 +38,7 @@ void read_floating_point(State& ps, Consumer&& consumer,
enum sign_t { plus, minus }; enum sign_t { plus, minus };
sign_t sign; sign_t sign;
ValueType result; ValueType result;
if (start_value == none) { if (!start_value) {
sign = plus; sign = plus;
result = 0; result = 0;
} else if (*start_value < 0) { } else if (*start_value < 0) {
...@@ -72,8 +72,8 @@ void read_floating_point(State& ps, Consumer&& consumer, ...@@ -72,8 +72,8 @@ void read_floating_point(State& ps, Consumer&& consumer,
} }
// 3) Scale result. // 3) Scale result.
// Pre-computed powers of 10 for the scaling loop. // Pre-computed powers of 10 for the scaling loop.
static double powerTable[] static double powerTable[] = {1e1, 1e2, 1e4, 1e8, 1e16,
= {1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 1e64, 1e128, 1e256}; 1e32, 1e64, 1e128, 1e256};
auto i = 0; auto i = 0;
if (exp < 0) { if (exp < 0) {
for (auto n = -exp; n != 0; n >>= 1, ++i) for (auto n = -exp; n != 0; n >>= 1, ++i)
...@@ -97,7 +97,7 @@ void read_floating_point(State& ps, Consumer&& consumer, ...@@ -97,7 +97,7 @@ void read_floating_point(State& ps, Consumer&& consumer,
// Definition of our parser FSM. // Definition of our parser FSM.
start(); start();
unstable_state(init) { unstable_state(init) {
epsilon_if(start_value == none, regular_init) epsilon_if(!start_value, regular_init)
epsilon(after_dec, "eE.") epsilon(after_dec, "eE.")
epsilon(after_dot, any_char) epsilon(after_dot, any_char)
} }
...@@ -173,7 +173,7 @@ template <class State, class Consumer> ...@@ -173,7 +173,7 @@ template <class State, class Consumer>
void read_floating_point(State& ps, Consumer&& consumer) { void read_floating_point(State& ps, Consumer&& consumer) {
using consumer_type = typename std::decay<Consumer>::type; using consumer_type = typename std::decay<Consumer>::type;
using value_type = typename consumer_type::value_type; using value_type = typename consumer_type::value_type;
return read_floating_point(ps, consumer, optional<value_type>{}); return read_floating_point(ps, consumer, std::optional<value_type>{});
} }
} // namespace caf::detail::parser } // namespace caf::detail::parser
......
...@@ -50,7 +50,7 @@ void read_number(State& ps, Consumer& consumer, EnableFloat = {}, ...@@ -50,7 +50,7 @@ void read_number(State& ps, Consumer& consumer, EnableFloat = {},
if (ps.code <= pec::trailing_character) if (ps.code <= pec::trailing_character)
consumer.value(result); consumer.value(result);
}); });
using odbl = optional<double>; using odbl = std::optional<double>;
// clang-format off // clang-format off
// Definition of our parser FSM. // Definition of our parser FSM.
start(); start();
...@@ -179,8 +179,8 @@ void read_number(State& ps, Consumer& consumer, EnableFloat = {}, ...@@ -179,8 +179,8 @@ void read_number(State& ps, Consumer& consumer, EnableFloat = {},
template <class State, class Consumer> template <class State, class Consumer>
void read_number_range(State& ps, Consumer& consumer, int64_t begin) { void read_number_range(State& ps, Consumer& consumer, int64_t begin) {
optional<int64_t> end; std::optional<int64_t> end;
optional<int64_t> step; std::optional<int64_t> step;
auto end_consumer = make_consumer(end); auto end_consumer = make_consumer(end);
auto step_consumer = make_consumer(step); auto step_consumer = make_consumer(step);
auto generate_2 = [&](int64_t n, int64_t m) { auto generate_2 = [&](int64_t n, int64_t m) {
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
#include <optional>
#include <string> #include <string>
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/detail/parser/read_signed_integer.hpp" #include "caf/detail/parser/read_signed_integer.hpp"
#include "caf/detail/scope_guard.hpp" #include "caf/detail/scope_guard.hpp"
#include "caf/optional.hpp"
#include "caf/pec.hpp" #include "caf/pec.hpp"
#include "caf/timestamp.hpp" #include "caf/timestamp.hpp"
...@@ -24,7 +24,7 @@ namespace caf::detail::parser { ...@@ -24,7 +24,7 @@ namespace caf::detail::parser {
/// Reads a timespan. /// Reads a timespan.
template <class State, class Consumer> template <class State, class Consumer>
void read_timespan(State& ps, Consumer&& consumer, void read_timespan(State& ps, Consumer&& consumer,
optional<int64_t> num = none) { std::optional<int64_t> num = std::nullopt) {
using namespace std::chrono; using namespace std::chrono;
struct interim_consumer { struct interim_consumer {
using value_type = int64_t; using value_type = int64_t;
......
...@@ -191,7 +191,7 @@ public: ...@@ -191,7 +191,7 @@ public:
} }
template <class T> template <class T>
bool builtin_inspect(const optional<T>& x) { bool builtin_inspect(const std::optional<T>& x) {
sep(); sep();
if (!x) { if (!x) {
result_ += "null"; result_ += "null";
......
...@@ -26,7 +26,7 @@ template <class> class expected; ...@@ -26,7 +26,7 @@ template <class> class expected;
template <class> class inbound_stream_slot; template <class> class inbound_stream_slot;
template <class> class intrusive_cow_ptr; template <class> class intrusive_cow_ptr;
template <class> class intrusive_ptr; template <class> class intrusive_ptr;
template <class> class optional; template <class> class [[deprecated ("use std::optional instead")]] optional;
template <class> class param; template <class> class param;
template <class> class span; template <class> class span;
template <class> class stream; template <class> class stream;
......
...@@ -329,6 +329,8 @@ struct inspector_access; ...@@ -329,6 +329,8 @@ struct inspector_access;
// -- inspection support for optional values ----------------------------------- // -- inspection support for optional values -----------------------------------
CAF_PUSH_DEPRECATED_WARNING
template <class T> template <class T>
struct optional_inspector_traits; struct optional_inspector_traits;
...@@ -344,6 +346,8 @@ struct optional_inspector_traits<optional<T>> { ...@@ -344,6 +346,8 @@ struct optional_inspector_traits<optional<T>> {
} }
}; };
CAF_POP_WARNINGS
template <class T> template <class T>
struct optional_inspector_traits<intrusive_ptr<T>> { struct optional_inspector_traits<intrusive_ptr<T>> {
using container_type = intrusive_ptr<T>; using container_type = intrusive_ptr<T>;
...@@ -441,11 +445,15 @@ struct optional_inspector_access { ...@@ -441,11 +445,15 @@ struct optional_inspector_access {
// -- inspection support for optional<T> --------------------------------------- // -- inspection support for optional<T> ---------------------------------------
CAF_PUSH_DEPRECATED_WARNING
template <class T> template <class T>
struct inspector_access<optional<T>> : optional_inspector_access<optional<T>> { struct inspector_access<optional<T>> : optional_inspector_access<optional<T>> {
// nop // nop
}; };
CAF_POP_WARNINGS
#ifdef CAF_HAS_STD_OPTIONAL #ifdef CAF_HAS_STD_OPTIONAL
template <class T> template <class T>
......
...@@ -72,8 +72,8 @@ public: ...@@ -72,8 +72,8 @@ public:
void assign(message_handler what); void assign(message_handler what);
/// Runs this handler and returns its (optional) result. /// Runs this handler and returns its (optional) result.
optional<message> operator()(message& arg) { std::optional<message> operator()(message& arg) {
return (impl_) ? impl_->invoke(arg) : none; return (impl_) ? impl_->invoke(arg) : std::nullopt;
} }
/// Runs this handler with callback. /// Runs this handler with callback.
......
...@@ -279,7 +279,7 @@ CAF_CORE_EXPORT node_id make_node_id( ...@@ -279,7 +279,7 @@ CAF_CORE_EXPORT node_id make_node_id(
/// @param process_id System-wide unique process identifier. /// @param process_id System-wide unique process identifier.
/// @param host_hash Unique node ID as hexadecimal string representation. /// @param host_hash Unique node ID as hexadecimal string representation.
/// @relates node_id /// @relates node_id
CAF_CORE_EXPORT optional<node_id> make_node_id(uint32_t process_id, CAF_CORE_EXPORT std::optional<node_id> make_node_id(uint32_t process_id,
string_view host_hash); string_view host_hash);
/// @relates node_id /// @relates node_id
......
...@@ -268,6 +268,8 @@ private: ...@@ -268,6 +268,8 @@ private:
bool m_value; bool m_value;
}; };
CAF_PUSH_DEPRECATED_WARNING
/// @relates optional /// @relates optional
template <class T> template <class T>
auto to_string(const optional<T>& x) auto to_string(const optional<T>& x)
...@@ -476,4 +478,6 @@ bool operator>=(const T& lhs, const optional<T>& rhs) { ...@@ -476,4 +478,6 @@ bool operator>=(const T& lhs, const optional<T>& rhs) {
return !rhs || !(lhs < *rhs); return !rhs || !(lhs < *rhs);
} }
CAF_POP_WARNINGS
} // namespace caf } // namespace caf
...@@ -189,7 +189,7 @@ public: ...@@ -189,7 +189,7 @@ public:
/// Returns a new URI with the `authority` component only. /// Returns a new URI with the `authority` component only.
/// @returns A new URI in the form `scheme://authority` if the authority /// @returns A new URI in the form `scheme://authority` if the authority
/// exists, otherwise `none`.` /// exists, otherwise `none`.`
optional<uri> authority_only() const; std::optional<uri> authority_only() const;
// -- comparison ------------------------------------------------------------- // -- comparison -------------------------------------------------------------
......
...@@ -235,9 +235,10 @@ auto make_actor_metric_families(telemetry::metric_registry& reg) { ...@@ -235,9 +235,10 @@ auto make_actor_metric_families(telemetry::metric_registry& reg) {
5., // 5s 5., // 5s
}}; }};
return actor_system::actor_metric_families_t{ return actor_system::actor_metric_families_t{
reg.histogram_family<double>( reg.histogram_family<double>("caf.actor", "processing-time", {"name"},
"caf.actor", "processing-time", {"name"}, default_buckets, default_buckets,
"Time an actor needs to process messages.", "seconds"), "Time an actor needs to process messages.",
"seconds"),
reg.histogram_family<double>( reg.histogram_family<double>(
"caf.actor", "mailbox-time", {"name"}, default_buckets, "caf.actor", "mailbox-time", {"name"}, default_buckets,
"Time a message waits in the mailbox before processing.", "seconds"), "Time a message waits in the mailbox before processing.", "seconds"),
...@@ -515,7 +516,7 @@ void actor_system::thread_terminates() { ...@@ -515,7 +516,7 @@ void actor_system::thread_terminates() {
expected<strong_actor_ptr> expected<strong_actor_ptr>
actor_system::dyn_spawn_impl(const std::string& name, message& args, actor_system::dyn_spawn_impl(const std::string& name, message& args,
execution_unit* ctx, bool check_interface, execution_unit* ctx, bool check_interface,
optional<const mpi&> expected_ifs) { const mpi* expected_ifs) {
CAF_LOG_TRACE(CAF_ARG(name) << CAF_ARG(args) << CAF_ARG(check_interface) CAF_LOG_TRACE(CAF_ARG(name) << CAF_ARG(args) << CAF_ARG(check_interface)
<< CAF_ARG(expected_ifs)); << CAF_ARG(expected_ifs));
if (name.empty()) if (name.empty())
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "caf/config_value.hpp" #include "caf/config_value.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/expected.hpp" #include "caf/expected.hpp"
#include "caf/optional.hpp"
using std::move; using std::move;
using std::string; using std::string;
...@@ -24,10 +23,9 @@ namespace caf { ...@@ -24,10 +23,9 @@ namespace caf {
config_option::config_option(string_view category, string_view name, config_option::config_option(string_view category, string_view name,
string_view description, const meta_state* meta, string_view description, const meta_state* meta,
void* value) void* value)
: meta_(meta), : meta_(meta), value_(value) {
value_(value) {
using std::copy;
using std::accumulate; using std::accumulate;
using std::copy;
auto comma = name.find(','); auto comma = name.find(',');
auto long_name = name.substr(0, comma); auto long_name = name.substr(0, comma);
auto short_names = comma == string_view::npos ? string_view{} auto short_names = comma == string_view::npos ? string_view{}
...@@ -44,9 +42,7 @@ config_option::config_option(string_view category, string_view name, ...@@ -44,9 +42,7 @@ config_option::config_option(string_view category, string_view name,
// fill the buffer with "<category>.<long-name>,<short-name>,<descriptions>" // fill the buffer with "<category>.<long-name>,<short-name>,<descriptions>"
auto first = buf_.get(); auto first = buf_.get();
auto i = first; auto i = first;
auto pos = [&] { auto pos = [&] { return static_cast<uint16_t>(std::distance(first, i)); };
return static_cast<uint16_t>(std::distance(first, i));
};
// <category>. // <category>.
i = copy(category.begin(), category.end(), i); i = copy(category.begin(), category.end(), i);
category_separator_ = pos(); category_separator_ = pos();
...@@ -143,10 +139,10 @@ expected<config_value> config_option::parse(string_view input) const { ...@@ -143,10 +139,10 @@ expected<config_value> config_option::parse(string_view input) const {
return {std::move(val)}; return {std::move(val)};
} }
optional<config_value> config_option::get() const { std::optional<config_value> config_option::get() const {
if (value_ != nullptr && meta_->get != nullptr) if (value_ != nullptr && meta_->get != nullptr)
return meta_->get(value_); return meta_->get(value_);
return none; return std::nullopt;
} }
string_view config_option::buf_slice(size_t from, size_t to) const noexcept { string_view config_option::buf_slice(size_t from, size_t to) const noexcept {
......
...@@ -499,7 +499,7 @@ bool config_value::can_convert_to_dictionary() const { ...@@ -499,7 +499,7 @@ bool config_value::can_convert_to_dictionary() const {
return visit(f, data_); return visit(f, data_);
} }
optional<message> std::optional<message>
config_value::parse_msg_impl(string_view str, config_value::parse_msg_impl(string_view str,
span<const type_id_list> allowed_types) { span<const type_id_list> allowed_types) {
if (auto val = parse(str)) { if (auto val = parse(str)) {
...@@ -533,7 +533,7 @@ config_value::parse_msg_impl(string_view str, ...@@ -533,7 +533,7 @@ config_value::parse_msg_impl(string_view str,
if (std::any_of(allowed_types.begin(), allowed_types.end(), converts)) if (std::any_of(allowed_types.begin(), allowed_types.end(), converts))
return {std::move(result)}; return {std::move(result)};
} }
return {}; return std::nullopt;
} }
// -- related free functions --------------------------------------------------- // -- related free functions ---------------------------------------------------
......
...@@ -36,7 +36,7 @@ private: ...@@ -36,7 +36,7 @@ private:
class maybe_message_visitor : public detail::invoke_result_visitor { class maybe_message_visitor : public detail::invoke_result_visitor {
public: public:
optional<message> value; std::optional<message> value;
void operator()(error& x) override { void operator()(error& x) override {
value = make_message(std::move(x)); value = make_message(std::move(x));
...@@ -66,11 +66,11 @@ bool behavior_impl::invoke_empty(detail::invoke_result_visitor& f) { ...@@ -66,11 +66,11 @@ bool behavior_impl::invoke_empty(detail::invoke_result_visitor& f) {
return invoke(f, xs); return invoke(f, xs);
} }
optional<message> behavior_impl::invoke(message& xs) { std::optional<message> behavior_impl::invoke(message& xs) {
maybe_message_visitor f; maybe_message_visitor f;
if (invoke(f, xs)) if (invoke(f, xs))
return std::move(f.value); return std::move(f.value);
return none; return std::nullopt;
} }
void behavior_impl::handle_timeout() { void behavior_impl::handle_timeout() {
......
...@@ -190,23 +190,24 @@ node_id make_node_id(uint32_t process_id, ...@@ -190,23 +190,24 @@ node_id make_node_id(uint32_t process_id,
return node_id{node_id::default_data{process_id, host_id}}; return node_id{node_id::default_data{process_id, host_id}};
} }
optional<node_id> make_node_id(uint32_t process_id, string_view host_hash) { std::optional<node_id> make_node_id(uint32_t process_id,
string_view host_hash) {
using id_type = hashed_node_id::host_id_type; using id_type = hashed_node_id::host_id_type;
if (host_hash.size() != std::tuple_size<id_type>::value * 2) if (host_hash.size() != std::tuple_size<id_type>::value * 2)
return none; return std::nullopt;
detail::parser::ascii_to_int<16, uint8_t> xvalue; detail::parser::ascii_to_int<16, uint8_t> xvalue;
id_type host_id; id_type host_id;
auto in = host_hash.begin(); auto in = host_hash.begin();
for (auto& byte : host_id) { for (auto& byte : host_id) {
if (!isxdigit(*in)) if (!isxdigit(*in))
return none; return std::nullopt;
auto first_nibble = (xvalue(*in++) << 4); auto first_nibble = (xvalue(*in++) << 4);
if (!isxdigit(*in)) if (!isxdigit(*in))
return none; return std::nullopt;
byte = static_cast<uint8_t>(first_nibble | xvalue(*in++)); byte = static_cast<uint8_t>(first_nibble | xvalue(*in++));
} }
if (!hashed_node_id::valid(host_id)) if (!hashed_node_id::valid(host_id))
return none; return std::nullopt;
return make_node_id(process_id, host_id); return make_node_id(process_id, host_id);
} }
......
...@@ -695,7 +695,7 @@ invoke_message_result scheduled_actor::consume(mailbox_element& x) { ...@@ -695,7 +695,7 @@ invoke_message_result scheduled_actor::consume(mailbox_element& x) {
using ptr_t = scheduled_actor*; using ptr_t = scheduled_actor*;
using fun_t = bool (*)(ptr_t, behavior&, mailbox_element&); using fun_t = bool (*)(ptr_t, behavior&, mailbox_element&);
auto ordinary_invoke = [](ptr_t, behavior& f, mailbox_element& in) -> bool { auto ordinary_invoke = [](ptr_t, behavior& f, mailbox_element& in) -> bool {
return f(in.content()) != none; return f(in.content()) != std::nullopt;
}; };
auto select_invoke_fun = [&]() -> fun_t { return ordinary_invoke; }; auto select_invoke_fun = [&]() -> fun_t { return ordinary_invoke; };
// Short-circuit awaited responses. // Short-circuit awaited responses.
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "caf/uri.hpp" #include "caf/uri.hpp"
#include <optional>
#include "caf/binary_deserializer.hpp" #include "caf/binary_deserializer.hpp"
#include "caf/binary_serializer.hpp" #include "caf/binary_serializer.hpp"
#include "caf/deserializer.hpp" #include "caf/deserializer.hpp"
...@@ -15,7 +17,6 @@ ...@@ -15,7 +17,6 @@
#include "caf/expected.hpp" #include "caf/expected.hpp"
#include "caf/hash/fnv.hpp" #include "caf/hash/fnv.hpp"
#include "caf/make_counted.hpp" #include "caf/make_counted.hpp"
#include "caf/optional.hpp"
#include "caf/serializer.hpp" #include "caf/serializer.hpp"
namespace { namespace {
...@@ -78,9 +79,9 @@ size_t uri::hash_code() const noexcept { ...@@ -78,9 +79,9 @@ size_t uri::hash_code() const noexcept {
return hash::fnv<size_t>::compute(str()); return hash::fnv<size_t>::compute(str());
} }
optional<uri> uri::authority_only() const { std::optional<uri> uri::authority_only() const {
if (empty() || authority().empty()) if (empty() || authority().empty())
return none; return std::nullopt;
auto result = make_counted<uri::impl_type>(); auto result = make_counted<uri::impl_type>();
result->scheme = impl_->scheme; result->scheme = impl_->scheme;
result->authority = impl_->authority; result->authority = impl_->authority;
......
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
#include <functional> #include <functional>
#include "caf/send.hpp"
#include "caf/behavior.hpp"
#include "caf/actor_system.hpp" #include "caf/actor_system.hpp"
#include "caf/message_handler.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/behavior.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/message_handler.hpp"
#include "caf/send.hpp"
using namespace caf; using namespace caf;
...@@ -39,13 +39,13 @@ public: ...@@ -39,13 +39,13 @@ public:
}; };
struct fixture { struct fixture {
optional<int32_t> res_of(behavior& bhvr, message& msg) { std::optional<int32_t> res_of(behavior& bhvr, message& msg) {
auto res = bhvr(msg); auto res = bhvr(msg);
if (!res) if (!res)
return none; return std::nullopt;
if (auto view = make_const_typed_message_view<int32_t>(*res)) if (auto view = make_const_typed_message_view<int32_t>(*res))
return get<0>(view); return get<0>(view);
return none; return std::nullopt;
} }
message m1 = make_message(int32_t{1}); message m1 = make_message(int32_t{1});
...@@ -61,33 +61,35 @@ CAF_TEST_FIXTURE_SCOPE(behavior_tests, fixture) ...@@ -61,33 +61,35 @@ CAF_TEST_FIXTURE_SCOPE(behavior_tests, fixture)
CAF_TEST(default_construct) { CAF_TEST(default_construct) {
behavior f; behavior f;
CAF_CHECK_EQUAL(f(m1), none); CAF_CHECK_EQUAL(f(m1), std::nullopt);
CAF_CHECK_EQUAL(f(m2), none); CAF_CHECK_EQUAL(f(m2), std::nullopt);
CAF_CHECK_EQUAL(f(m3), none); CAF_CHECK_EQUAL(f(m3), std::nullopt);
} }
CAF_TEST(nocopy_function_object) { CAF_TEST(nocopy_function_object) {
behavior f{nocopy_fun{}}; behavior f{nocopy_fun{}};
CAF_CHECK_EQUAL(f(m1), none); CAF_CHECK_EQUAL(f(m1), std::nullopt);
CAF_CHECK_EQUAL(res_of(f, m2), 3); CAF_CHECK_EQUAL(res_of(f, m2), 3);
CAF_CHECK_EQUAL(f(m3), none); CAF_CHECK_EQUAL(f(m3), std::nullopt);
} }
CAF_TEST(single_lambda_construct) { CAF_TEST(single_lambda_construct) {
behavior f{[](int x) { return x + 1; }}; behavior f{
[](int x) { return x + 1; },
};
CAF_CHECK_EQUAL(res_of(f, m1), 2); CAF_CHECK_EQUAL(res_of(f, m1), 2);
CAF_CHECK_EQUAL(res_of(f, m2), none); CAF_CHECK_EQUAL(res_of(f, m2), std::nullopt);
CAF_CHECK_EQUAL(res_of(f, m3), none); CAF_CHECK_EQUAL(res_of(f, m3), std::nullopt);
} }
CAF_TEST(multiple_lambda_construct) { CAF_TEST(multiple_lambda_construct) {
behavior f{ behavior f{
[](int x) { return x + 1; }, [](int x) { return x + 1; },
[](int x, int y) { return x * y; } [](int x, int y) { return x * y; },
}; };
CAF_CHECK_EQUAL(res_of(f, m1), 2); CAF_CHECK_EQUAL(res_of(f, m1), 2);
CAF_CHECK_EQUAL(res_of(f, m2), 2); CAF_CHECK_EQUAL(res_of(f, m2), 2);
CAF_CHECK_EQUAL(res_of(f, m3), none); CAF_CHECK_EQUAL(res_of(f, m3), std::nullopt);
} }
CAF_TEST(become_empty_behavior) { CAF_TEST(become_empty_behavior) {
...@@ -95,7 +97,7 @@ CAF_TEST(become_empty_behavior) { ...@@ -95,7 +97,7 @@ CAF_TEST(become_empty_behavior) {
actor_system sys{cfg}; actor_system sys{cfg};
auto make_bhvr = [](event_based_actor* self) -> behavior { auto make_bhvr = [](event_based_actor* self) -> behavior {
return { return {
[=](int) { self->become(behavior{}); } [=](int) { self->become(behavior{}); },
}; };
}; };
anon_send(sys.spawn(make_bhvr), int{5}); anon_send(sys.spawn(make_bhvr), int{5});
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#include <sstream> #include <sstream>
#include "caf/make_config_option.hpp"
#include "caf/config_value.hpp" #include "caf/config_value.hpp"
#include "caf/expected.hpp" #include "caf/expected.hpp"
#include "caf/make_config_option.hpp"
using namespace caf; using namespace caf;
...@@ -173,25 +173,25 @@ constexpr string_view category = "category"; ...@@ -173,25 +173,25 @@ constexpr string_view category = "category";
constexpr string_view name = "name"; constexpr string_view name = "name";
constexpr string_view explanation = "explanation"; constexpr string_view explanation = "explanation";
template<class T> template <class T>
constexpr int64_t overflow() { constexpr int64_t overflow() {
return static_cast<int64_t>(std::numeric_limits<T>::max()) + 1; return static_cast<int64_t>(std::numeric_limits<T>::max()) + 1;
} }
template<class T> template <class T>
constexpr int64_t underflow() { constexpr int64_t underflow() {
return static_cast<int64_t>(std::numeric_limits<T>::min()) - 1; return static_cast<int64_t>(std::numeric_limits<T>::min()) - 1;
} }
template <class T> template <class T>
optional<T> read(string_view arg) { std::optional<T> read(string_view arg) {
auto result = T{}; auto result = T{};
auto co = make_config_option<T>(result, category, name, explanation); auto co = make_config_option<T>(result, category, name, explanation);
config_value val{arg}; config_value val{arg};
if (auto err = co.sync(val); !err) if (auto err = co.sync(val); !err)
return {std::move(result)}; return {std::move(result)};
else else
return none; return std::nullopt;
} }
// Unsigned integers. // Unsigned integers.
...@@ -203,7 +203,7 @@ void check_integer_options(std::true_type) { ...@@ -203,7 +203,7 @@ void check_integer_options(std::true_type) {
T xmax = std::numeric_limits<T>::max(); T xmax = std::numeric_limits<T>::max();
CAF_CHECK_EQUAL(read<T>(to_string(xzero)), xzero); CAF_CHECK_EQUAL(read<T>(to_string(xzero)), xzero);
CAF_CHECK_EQUAL(read<T>(to_string(xmax)), xmax); CAF_CHECK_EQUAL(read<T>(to_string(xmax)), xmax);
CAF_CHECK_EQUAL(read<T>(to_string(overflow<T>())), none); CAF_CHECK_EQUAL(read<T>(to_string(overflow<T>())), std::nullopt);
} }
// Signed integers. // Signed integers.
...@@ -216,7 +216,7 @@ void check_integer_options(std::false_type) { ...@@ -216,7 +216,7 @@ void check_integer_options(std::false_type) {
// Run tests for negative integers. // Run tests for negative integers.
auto xmin = std::numeric_limits<T>::min(); auto xmin = std::numeric_limits<T>::min();
CAF_CHECK_EQUAL(read<T>(to_string(xmin)), xmin); CAF_CHECK_EQUAL(read<T>(to_string(xmin)), xmin);
CAF_CHECK_EQUAL(read<T>(to_string(underflow<T>())), none); CAF_CHECK_EQUAL(read<T>(to_string(underflow<T>())), std::nullopt);
} }
// only works with an integral types and double // only works with an integral types and double
...@@ -250,8 +250,8 @@ CAF_TEST(copy assignment) { ...@@ -250,8 +250,8 @@ CAF_TEST(copy assignment) {
CAF_TEST(type_bool) { CAF_TEST(type_bool) {
CAF_CHECK_EQUAL(read<bool>("true"), true); CAF_CHECK_EQUAL(read<bool>("true"), true);
CAF_CHECK_EQUAL(read<bool>("false"), false); CAF_CHECK_EQUAL(read<bool>("false"), false);
CAF_CHECK_EQUAL(read<bool>("0"), none); CAF_CHECK_EQUAL(read<bool>("0"), std::nullopt);
CAF_CHECK_EQUAL(read<bool>("1"), none); CAF_CHECK_EQUAL(read<bool>("1"), std::nullopt);
} }
CAF_TEST(type int8_t) { CAF_TEST(type int8_t) {
...@@ -280,7 +280,7 @@ CAF_TEST(type uint32_t) { ...@@ -280,7 +280,7 @@ CAF_TEST(type uint32_t) {
CAF_TEST(type uint64_t) { CAF_TEST(type uint64_t) {
CAF_CHECK_EQUAL(unbox(read<uint64_t>("0")), 0u); CAF_CHECK_EQUAL(unbox(read<uint64_t>("0")), 0u);
CAF_CHECK_EQUAL(read<uint64_t>("-1"), none); CAF_CHECK_EQUAL(read<uint64_t>("-1"), std::nullopt);
} }
CAF_TEST(type int64_t) { CAF_TEST(type int64_t) {
...@@ -293,14 +293,14 @@ CAF_TEST(type float) { ...@@ -293,14 +293,14 @@ CAF_TEST(type float) {
CAF_CHECK_EQUAL(unbox(read<float>("-1.0")), -1.0f); CAF_CHECK_EQUAL(unbox(read<float>("-1.0")), -1.0f);
CAF_CHECK_EQUAL(unbox(read<float>("-0.1")), -0.1f); CAF_CHECK_EQUAL(unbox(read<float>("-0.1")), -0.1f);
CAF_CHECK_EQUAL(read<float>("0"), 0.f); CAF_CHECK_EQUAL(read<float>("0"), 0.f);
CAF_CHECK_EQUAL(read<float>("\"0.1\""), none); CAF_CHECK_EQUAL(read<float>("\"0.1\""), std::nullopt);
} }
CAF_TEST(type double) { CAF_TEST(type double) {
CAF_CHECK_EQUAL(unbox(read<double>("-1.0")), -1.0); CAF_CHECK_EQUAL(unbox(read<double>("-1.0")), -1.0);
CAF_CHECK_EQUAL(unbox(read<double>("-0.1")), -0.1); CAF_CHECK_EQUAL(unbox(read<double>("-0.1")), -0.1);
CAF_CHECK_EQUAL(read<double>("0"), 0.); CAF_CHECK_EQUAL(read<double>("0"), 0.);
CAF_CHECK_EQUAL(read<double>("\"0.1\""), none); CAF_CHECK_EQUAL(read<double>("\"0.1\""), std::nullopt);
} }
CAF_TEST(type string) { CAF_TEST(type string) {
......
...@@ -380,7 +380,7 @@ bool inspect(Inspector& f, widget& x) { ...@@ -380,7 +380,7 @@ bool inspect(Inspector& f, widget& x) {
struct dummy_user { struct dummy_user {
std::string name; std::string name;
caf::optional<std::string> nickname; std::optional<std::string> nickname;
}; };
template <class Inspector> template <class Inspector>
......
...@@ -43,8 +43,8 @@ CAF_TEST(pointers and optionals use dereference syntax) { ...@@ -43,8 +43,8 @@ CAF_TEST(pointers and optionals use dereference syntax) {
auto i = 42; auto i = 42;
CHECK_DEEP_TO_STRING(&i, "*42"); CHECK_DEEP_TO_STRING(&i, "*42");
CHECK_DEEP_TO_STRING(static_cast<int*>(nullptr), "null"); CHECK_DEEP_TO_STRING(static_cast<int*>(nullptr), "null");
CHECK_DEEP_TO_STRING(optional<int>{}, "null"); CHECK_DEEP_TO_STRING(std::optional<int>{}, "null");
CHECK_DEEP_TO_STRING(optional<int>{23}, "*23"); CHECK_DEEP_TO_STRING(std::optional<int>{23}, "*23");
} }
CAF_TEST(buffers) { CAF_TEST(buffers) {
......
...@@ -28,12 +28,12 @@ struct double_consumer { ...@@ -28,12 +28,12 @@ struct double_consumer {
double x; double x;
}; };
optional<double> read(string_view str) { std::optional<double> read(string_view str) {
double_consumer consumer; double_consumer consumer;
string_parser_state ps{str.begin(), str.end()}; string_parser_state ps{str.begin(), str.end()};
detail::parser::read_floating_point(ps, consumer); detail::parser::read_floating_point(ps, consumer);
if (ps.code != pec::success) if (ps.code != pec::success)
return none; return std::nullopt;
return consumer.x; return consumer.x;
} }
......
...@@ -28,12 +28,12 @@ struct signed_integer_consumer { ...@@ -28,12 +28,12 @@ struct signed_integer_consumer {
}; };
template <class T> template <class T>
optional<T> read(string_view str) { std::optional<T> read(string_view str) {
signed_integer_consumer<T> consumer; signed_integer_consumer<T> consumer;
string_parser_state ps{str.begin(), str.end()}; string_parser_state ps{str.begin(), str.end()};
detail::parser::read_signed_integer(ps, consumer); detail::parser::read_signed_integer(ps, consumer);
if (ps.code != pec::success) if (ps.code != pec::success)
return none; return std::nullopt;
return consumer.x; return consumer.x;
} }
......
...@@ -50,12 +50,12 @@ struct timespan_consumer { ...@@ -50,12 +50,12 @@ struct timespan_consumer {
timespan x; timespan x;
}; };
optional<timespan> read(string_view str) { std::optional<timespan> read(string_view str) {
timespan_consumer consumer; timespan_consumer consumer;
string_parser_state ps{str.begin(), str.end()}; string_parser_state ps{str.begin(), str.end()};
detail::parser::read_timespan(ps, consumer); detail::parser::read_timespan(ps, consumer);
if (ps.code != pec::success) if (ps.code != pec::success)
return none; return std::nullopt;
return consumer.x; return consumer.x;
} }
......
...@@ -28,12 +28,12 @@ struct unsigned_integer_consumer { ...@@ -28,12 +28,12 @@ struct unsigned_integer_consumer {
}; };
template <class T> template <class T>
optional<T> read(string_view str) { std::optional<T> read(string_view str) {
unsigned_integer_consumer<T> consumer; unsigned_integer_consumer<T> consumer;
string_parser_state ps{str.begin(), str.end()}; string_parser_state ps{str.begin(), str.end()};
detail::parser::read_unsigned_integer(ps, consumer); detail::parser::read_unsigned_integer(ps, consumer);
if (ps.code != pec::success) if (ps.code != pec::success)
return none; return std::nullopt;
return consumer.x; return consumer.x;
} }
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
#pragma once #pragma once
#include "caf/optional.hpp"
#include "caf/type_id.hpp" #include "caf/type_id.hpp"
#include "caf/variant.hpp" #include "caf/variant.hpp"
#include <optional>
#include "nasty.hpp" #include "nasty.hpp"
namespace { namespace {
...@@ -89,7 +90,7 @@ bool inspect(Inspector& f, duration& x) { ...@@ -89,7 +90,7 @@ bool inspect(Inspector& f, duration& x) {
struct person { struct person {
std::string name; std::string name;
caf::optional<std::string> phone; std::optional<std::string> phone;
}; };
template <class Inspector> template <class Inspector>
......
...@@ -328,7 +328,7 @@ end object)_"); ...@@ -328,7 +328,7 @@ end object)_");
} }
CAF_TEST(load inspectors support optional) { CAF_TEST(load inspectors support optional) {
optional<int32_t> x; std::optional<int32_t> x;
CAF_CHECK_EQUAL(f.apply(x), true); CAF_CHECK_EQUAL(f.apply(x), true);
CAF_CHECK_EQUAL(f.log, R"_( CAF_CHECK_EQUAL(f.log, R"_(
begin object anonymous begin object anonymous
...@@ -356,7 +356,7 @@ CAF_TEST(load inspectors support fields with optional values) { ...@@ -356,7 +356,7 @@ CAF_TEST(load inspectors support fields with optional values) {
person p{"Bruce Almighty", std::string{"776-2323"}}; person p{"Bruce Almighty", std::string{"776-2323"}};
CAF_CHECK_EQUAL(inspect(f, p), true); CAF_CHECK_EQUAL(inspect(f, p), true);
CAF_CHECK_EQUAL(p.name, ""); CAF_CHECK_EQUAL(p.name, "");
CAF_CHECK_EQUAL(p.phone, none); CAF_CHECK_EQUAL(p.phone, std::nullopt);
CAF_CHECK_EQUAL(f.log, R"_( CAF_CHECK_EQUAL(f.log, R"_(
begin object person begin object person
begin field name begin field name
...@@ -752,7 +752,7 @@ SCENARIO("load inspectors support std::byte") { ...@@ -752,7 +752,7 @@ SCENARIO("load inspectors support std::byte") {
GIVEN("a struct with std::byte") { GIVEN("a struct with std::byte") {
struct byte_test { struct byte_test {
std::byte v1 = std::byte{0}; std::byte v1 = std::byte{0};
optional<std::byte> v2; std::optional<std::byte> v2;
}; };
auto x = byte_test{}; auto x = byte_test{};
WHEN("inspecting the struct") { WHEN("inspecting the struct") {
......
...@@ -24,44 +24,44 @@ using namespace caf; ...@@ -24,44 +24,44 @@ using namespace caf;
namespace { namespace {
template <class... Ts> template <class... Ts>
optional<tuple<Ts...>> fetch(const message& x) { std::optional<tuple<Ts...>> fetch(const message& x) {
if (auto view = make_const_typed_message_view<Ts...>(x)) if (auto view = make_const_typed_message_view<Ts...>(x))
return to_tuple(view); return to_tuple(view);
return none; return std::nullopt;
} }
template <class... Ts> template <class... Ts>
optional<tuple<Ts...>> fetch(const mailbox_element& x) { std::optional<tuple<Ts...>> fetch(const mailbox_element& x) {
return fetch<Ts...>(x.content()); return fetch<Ts...>(x.content());
} }
} // namespace } // namespace
CAF_TEST(empty_message) { CAF_TEST(empty_message) {
auto m1 = make_mailbox_element(nullptr, make_message_id(), auto m1 = make_mailbox_element(nullptr, make_message_id(), no_stages,
no_stages, make_message()); make_message());
CAF_CHECK(m1->mid.is_async()); CAF_CHECK(m1->mid.is_async());
CAF_CHECK(m1->mid.category() == message_id::normal_message_category); CAF_CHECK(m1->mid.category() == message_id::normal_message_category);
CAF_CHECK(m1->content().empty()); CAF_CHECK(m1->content().empty());
} }
CAF_TEST(non_empty_message) { CAF_TEST(non_empty_message) {
auto m1 = make_mailbox_element(nullptr, make_message_id(), auto m1 = make_mailbox_element(nullptr, make_message_id(), no_stages,
no_stages, make_message(1, 2, 3)); make_message(1, 2, 3));
CAF_CHECK(m1->mid.is_async()); CAF_CHECK(m1->mid.is_async());
CAF_CHECK(m1->mid.category() == message_id::normal_message_category); CAF_CHECK(m1->mid.category() == message_id::normal_message_category);
CAF_CHECK(!m1->content().empty()); CAF_CHECK(!m1->content().empty());
CAF_CHECK_EQUAL((fetch<int, int>(*m1)), none); CAF_CHECK_EQUAL((fetch<int, int>(*m1)), std::nullopt);
CAF_CHECK_EQUAL((fetch<int, int, int>(*m1)), make_tuple(1, 2, 3)); CAF_CHECK_EQUAL((fetch<int, int, int>(*m1)), make_tuple(1, 2, 3));
} }
CAF_TEST(tuple) { CAF_TEST(tuple) {
auto m1 = make_mailbox_element(nullptr, make_message_id(), auto m1 = make_mailbox_element(nullptr, make_message_id(), no_stages, 1, 2,
no_stages, 1, 2, 3); 3);
CAF_CHECK(m1->mid.is_async()); CAF_CHECK(m1->mid.is_async());
CAF_CHECK(m1->mid.category() == message_id::normal_message_category); CAF_CHECK(m1->mid.category() == message_id::normal_message_category);
CAF_CHECK(!m1->content().empty()); CAF_CHECK(!m1->content().empty());
CAF_CHECK_EQUAL((fetch<int, int>(*m1)), none); CAF_CHECK_EQUAL((fetch<int, int>(*m1)), std::nullopt);
CAF_CHECK_EQUAL((fetch<int, int, int>(*m1)), make_tuple(1, 2, 3)); CAF_CHECK_EQUAL((fetch<int, int, int>(*m1)), make_tuple(1, 2, 3));
} }
...@@ -79,9 +79,9 @@ CAF_TEST(upstream_msg_static) { ...@@ -79,9 +79,9 @@ CAF_TEST(upstream_msg_static) {
} }
CAF_TEST(upstream_msg_dynamic) { CAF_TEST(upstream_msg_dynamic) {
auto m1 = make_mailbox_element( auto m1 = make_mailbox_element(nullptr, make_message_id(), no_stages,
nullptr, make_message_id(), no_stages, make_message(
make_message(make<upstream_msg::drop>({0, 0}, nullptr))); make<upstream_msg::drop>({0, 0}, nullptr)));
CAF_CHECK(m1->mid.category() == message_id::upstream_message_category); CAF_CHECK(m1->mid.category() == message_id::upstream_message_category);
} }
......
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <optional>
#include <string> #include <string>
#include <tuple> #include <tuple>
#include "caf/inspector_access.hpp" #include "caf/inspector_access.hpp"
#include "caf/optional.hpp"
#include "caf/string_view.hpp" #include "caf/string_view.hpp"
#include "caf/variant.hpp" #include "caf/variant.hpp"
...@@ -60,15 +60,15 @@ class nasty { ...@@ -60,15 +60,15 @@ class nasty {
public: public:
static inline caf::string_view tname = "nasty"; static inline caf::string_view tname = "nasty";
using optional_type = caf::optional<int32_t>; using optional_type = std::optional<int32_t>;
using variant_type = caf::variant<std::string, int32_t>; using variant_type = caf::variant<std::string, int32_t>;
using tuple_type = std::tuple<std::string, int32_t>; using tuple_type = std::tuple<std::string, int32_t>;
using optional_variant_type = caf::optional<variant_type>; using optional_variant_type = std::optional<variant_type>;
using optional_tuple_type = caf::optional<tuple_type>; using optional_tuple_type = std::optional<tuple_type>;
// Plain, direct access. // Plain, direct access.
int32_t field_01 = 0; int32_t field_01 = 0;
...@@ -135,13 +135,13 @@ public: ...@@ -135,13 +135,13 @@ public:
// Optional, get/set access. // Optional, get/set access.
ADD_GET_SET_FIELD(optional_type, field_21) ADD_GET_SET_FIELD(optional_type, field_21)
// // Optional, get/set access, fallback (0). // Optional, get/set access, fallback (0).
// ADD_GET_SET_FIELD(optional_type, field_22) // ADD_GET_SET_FIELD(optional_type, field_22)
// Optional, get/set access, invariant (>= 0). // Optional, get/set access, invariant (>= 0).
ADD_GET_SET_FIELD(optional_type, field_23) ADD_GET_SET_FIELD(optional_type, field_23)
// // Optional, get/set access, fallback (0), invariant (>= 0). // Optional, get/set access, fallback (0), invariant (>= 0).
// ADD_GET_SET_FIELD(optional_type, field_24) // ADD_GET_SET_FIELD(optional_type, field_24)
// Variant, get/set access. // Variant, get/set access.
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
#define CAF_SUITE optional #define CAF_SUITE optional
#include "caf/optional.hpp"
#include "core-test.hpp" #include "core-test.hpp"
#include "caf/optional.hpp"
using namespace caf; using namespace caf;
namespace { namespace {
...@@ -26,6 +26,8 @@ bool operator==(const qwertz& lhs, const qwertz& rhs) { ...@@ -26,6 +26,8 @@ bool operator==(const qwertz& lhs, const qwertz& rhs) {
} // namespace } // namespace
CAF_PUSH_DEPRECATED_WARNING
CAF_TEST(empty) { CAF_TEST(empty) {
optional<int> x; optional<int> x;
optional<int> y; optional<int> y;
...@@ -70,7 +72,9 @@ CAF_TEST(custom_type_engaged) { ...@@ -70,7 +72,9 @@ CAF_TEST(custom_type_engaged) {
optional<qwertz> x = obj; optional<qwertz> x = obj;
CAF_CHECK(x != none); CAF_CHECK(x != none);
CAF_CHECK(obj == x); CAF_CHECK(obj == x);
CAF_CHECK(x == obj ); CAF_CHECK(x == obj);
CAF_CHECK(obj == *x); CAF_CHECK(obj == *x);
CAF_CHECK(*x == obj); CAF_CHECK(*x == obj);
} }
CAF_POP_WARNINGS
...@@ -419,7 +419,7 @@ end object)_"); ...@@ -419,7 +419,7 @@ end object)_");
} }
CAF_TEST(save inspectors support optional) { CAF_TEST(save inspectors support optional) {
optional<int32_t> x; std::optional<int32_t> x;
CAF_CHECK_EQUAL(f.apply(x), true); CAF_CHECK_EQUAL(f.apply(x), true);
CAF_CHECK_EQUAL(f.log, R"_( CAF_CHECK_EQUAL(f.log, R"_(
begin object anonymous begin object anonymous
...@@ -429,7 +429,7 @@ end object)_"); ...@@ -429,7 +429,7 @@ end object)_");
} }
CAF_TEST(save inspectors support fields with optional values) { CAF_TEST(save inspectors support fields with optional values) {
person p1{"Eduard Example", none}; person p1{"Eduard Example", std::nullopt};
CAF_CHECK_EQUAL(inspect(f, p1), true); CAF_CHECK_EQUAL(inspect(f, p1), true);
CAF_CHECK_EQUAL(f.log, R"_( CAF_CHECK_EQUAL(f.log, R"_(
begin object person begin object person
......
...@@ -386,12 +386,12 @@ protected: ...@@ -386,12 +386,12 @@ protected:
/// Returns a `scribe` or `doorman` identified by `hdl`. /// Returns a `scribe` or `doorman` identified by `hdl`.
template <class Handle> template <class Handle>
auto by_id(Handle hdl) -> optional<decltype(*ptr_of(hdl))> { auto by_id(Handle hdl) -> decltype(ptr_of(hdl)) {
auto& elements = get_map(hdl); auto& elements = get_map(hdl);
auto i = elements.find(hdl); auto i = elements.find(hdl);
if (i == elements.end()) if (i == elements.end())
return none; return nullptr;
return *(i->second); return std::addressof(*(i->second));
} }
private: private:
......
...@@ -31,7 +31,7 @@ struct endpoint_context { ...@@ -31,7 +31,7 @@ struct endpoint_context {
uint16_t remote_port; uint16_t remote_port;
uint16_t local_port; uint16_t local_port;
// pending operations to be performed after handshake completed // pending operations to be performed after handshake completed
optional<response_promise> callback; std::optional<response_promise> callback;
// keeps track of when we've last received a message from this endpoint // keeps track of when we've last received a message from this endpoint
actor_clock::time_point last_seen; actor_clock::time_point last_seen;
}; };
......
...@@ -103,14 +103,14 @@ public: ...@@ -103,14 +103,14 @@ public:
/// Handles received data and returns a config for receiving the /// Handles received data and returns a config for receiving the
/// next data or `none` if an error occurred. /// next data or `none` if an error occurred.
connection_state handle(execution_unit* ctx, connection_state handle(execution_unit* ctx, new_data_msg& dm, header& hdr,
new_data_msg& dm, header& hdr, bool is_payload); bool is_payload);
/// Sends heartbeat messages to all valid nodes those are directly connected. /// Sends heartbeat messages to all valid nodes those are directly connected.
void handle_heartbeat(execution_unit* ctx); void handle_heartbeat(execution_unit* ctx);
/// Returns a route to `target` or `none` on error. /// Returns a route to `target` or `none` on error.
optional<routing_table::route> lookup(const node_id& target); std::optional<routing_table::route> lookup(const node_id& target);
/// Flushes the underlying buffer of `path`. /// Flushes the underlying buffer of `path`.
void flush(const routing_table::route& path); void flush(const routing_table::route& path);
...@@ -125,8 +125,8 @@ public: ...@@ -125,8 +125,8 @@ public:
std::set<std::string> published_interface); std::set<std::string> published_interface);
/// Removes the actor currently assigned to `port`. /// Removes the actor currently assigned to `port`.
size_t size_t remove_published_actor(uint16_t port,
remove_published_actor(uint16_t port, removed_published_actor* cb = nullptr); removed_published_actor* cb = nullptr);
/// Removes `whom` if it is still assigned to `port` or from all of its /// Removes `whom` if it is still assigned to `port` or from all of its
/// current ports if `port == 0`. /// current ports if `port == 0`.
...@@ -171,7 +171,7 @@ public: ...@@ -171,7 +171,7 @@ public:
/// if no actor is published at this port then a standard handshake is /// if no actor is published at this port then a standard handshake is
/// written (e.g. used when establishing direct connections on-the-fly). /// written (e.g. used when establishing direct connections on-the-fly).
void write_server_handshake(execution_unit* ctx, byte_buffer& out_buf, void write_server_handshake(execution_unit* ctx, byte_buffer& out_buf,
optional<uint16_t> port); std::optional<uint16_t> port);
/// Writes the client handshake to `buf`. /// Writes the client handshake to `buf`.
void write_client_handshake(execution_unit* ctx, byte_buffer& buf); void write_client_handshake(execution_unit* ctx, byte_buffer& buf);
...@@ -181,9 +181,9 @@ public: ...@@ -181,9 +181,9 @@ public:
const node_id& dest_node, actor_id aid); const node_id& dest_node, actor_id aid);
/// Writes a `kill_proxy` to `buf`. /// Writes a `kill_proxy` to `buf`.
void void write_down_message(execution_unit* ctx, byte_buffer& buf,
write_down_message(execution_unit* ctx, byte_buffer& buf, const node_id& dest_node, actor_id aid,
const node_id& dest_node, actor_id aid, const error& rsn); const error& rsn);
/// Writes a `heartbeat` to `buf`. /// Writes a `heartbeat` to `buf`.
void write_heartbeat(execution_unit* ctx, byte_buffer& buf); void write_heartbeat(execution_unit* ctx, byte_buffer& buf);
......
...@@ -33,7 +33,7 @@ public: ...@@ -33,7 +33,7 @@ public:
}; };
/// Returns a route to `target` or `none` on error. /// Returns a route to `target` or `none` on error.
optional<route> lookup(const node_id& target); std::optional<route> lookup(const node_id& target);
/// Returns the ID of the peer connected via `hdl` or /// Returns the ID of the peer connected via `hdl` or
/// `none` if `hdl` is unknown. /// `none` if `hdl` is unknown.
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
/// Returns the handle offering a direct connection to `nid` or /// Returns the handle offering a direct connection to `nid` or
/// `invalid_connection_handle` if no direct connection to `nid` exists. /// `invalid_connection_handle` if no direct connection to `nid` exists.
optional<connection_handle> lookup_direct(const node_id& nid) const; std::optional<connection_handle> lookup_direct(const node_id& nid) const;
/// Returns the next hop that would be chosen for `nid` /// Returns the next hop that would be chosen for `nid`
/// or `none` if there's no indirect route to `nid`. /// or `none` if there's no indirect route to `nid`.
......
...@@ -32,12 +32,12 @@ public: ...@@ -32,12 +32,12 @@ public:
} }
void halt() { void halt() {
activity_tokens_ = none; activity_tokens_ = std::nullopt;
this->remove_from_loop(); this->remove_from_loop();
} }
void trigger() { void trigger() {
activity_tokens_ = none; activity_tokens_ = std::nullopt;
this->add_to_loop(); this->add_to_loop();
} }
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
this->add_to_loop(); this->add_to_loop();
} }
optional<size_t> activity_tokens() const { std::optional<size_t> activity_tokens() const {
return activity_tokens_; return activity_tokens_;
} }
...@@ -105,7 +105,7 @@ protected: ...@@ -105,7 +105,7 @@ protected:
handle_type hdl_; handle_type hdl_;
mailbox_element value_; mailbox_element value_;
optional<size_t> activity_tokens_; std::optional<size_t> activity_tokens_;
}; };
} // namespace caf::io } // namespace caf::io
...@@ -53,18 +53,18 @@ protected: ...@@ -53,18 +53,18 @@ protected:
/// Tries to connect to given `host` and `port`. The default implementation /// Tries to connect to given `host` and `port`. The default implementation
/// calls `system().middleman().backend().new_udp`. /// calls `system().middleman().backend().new_udp`.
virtual expected<datagram_servant_ptr> virtual expected<datagram_servant_ptr> contact(const std::string& host,
contact(const std::string& host, uint16_t port); uint16_t port);
/// Tries to open a local port. The default implementation calls /// Tries to open a local port. The default implementation calls
/// `system().middleman().backend().new_tcp_doorman(port, addr, reuse)`. /// `system().middleman().backend().new_tcp_doorman(port, addr, reuse)`.
virtual expected<doorman_ptr> virtual expected<doorman_ptr> open(uint16_t port, const char* addr,
open(uint16_t port, const char* addr, bool reuse); bool reuse);
/// Tries to open a local port. The default implementation calls /// Tries to open a local port. The default implementation calls
/// `system().middleman().backend().new_tcp_doorman(port, addr, reuse)`. /// `system().middleman().backend().new_tcp_doorman(port, addr, reuse)`.
virtual expected<datagram_servant_ptr> virtual expected<datagram_servant_ptr> open_udp(uint16_t port,
open_udp(uint16_t port, const char* addr, bool reuse); const char* addr, bool reuse);
private: private:
put_res put(uint16_t port, strong_actor_ptr& whom, mpi_set& sigs, put_res put(uint16_t port, strong_actor_ptr& whom, mpi_set& sigs,
...@@ -73,10 +73,10 @@ private: ...@@ -73,10 +73,10 @@ private:
put_res put_udp(uint16_t port, strong_actor_ptr& whom, mpi_set& sigs, put_res put_udp(uint16_t port, strong_actor_ptr& whom, mpi_set& sigs,
const char* in = nullptr, bool reuse_addr = false); const char* in = nullptr, bool reuse_addr = false);
optional<endpoint_data&> cached_tcp(const endpoint& ep); endpoint_data* cached_tcp(const endpoint& ep);
optional<endpoint_data&> cached_udp(const endpoint& ep); endpoint_data* cached_udp(const endpoint& ep);
optional<std::vector<response_promise>&> pending(const endpoint& ep); std::vector<response_promise>* pending(const endpoint& ep);
actor broker_; actor broker_;
std::map<endpoint, endpoint_data> cached_tcp_; std::map<endpoint, endpoint_data> cached_tcp_;
......
...@@ -101,13 +101,13 @@ public: ...@@ -101,13 +101,13 @@ public:
scribe_ptr new_scribe(native_socket fd) override; scribe_ptr new_scribe(native_socket fd) override;
expected<scribe_ptr> expected<scribe_ptr> new_tcp_scribe(const std::string& host,
new_tcp_scribe(const std::string& host, uint16_t port) override; uint16_t port) override;
doorman_ptr new_doorman(native_socket fd) override; doorman_ptr new_doorman(native_socket fd) override;
expected<doorman_ptr> expected<doorman_ptr> new_tcp_doorman(uint16_t port, const char* in,
new_tcp_doorman(uint16_t port, const char* in, bool reuse_addr) override; bool reuse_addr) override;
datagram_servant_ptr new_datagram_servant(native_socket fd) override; datagram_servant_ptr new_datagram_servant(native_socket fd) override;
...@@ -261,18 +261,20 @@ inline accept_handle accept_hdl_from_socket(native_socket fd) { ...@@ -261,18 +261,20 @@ inline accept_handle accept_hdl_from_socket(native_socket fd) {
CAF_IO_EXPORT expected<native_socket> CAF_IO_EXPORT expected<native_socket>
new_tcp_connection(const std::string& host, uint16_t port, new_tcp_connection(const std::string& host, uint16_t port,
optional<protocol::network> preferred = none); std::optional<protocol::network> preferred = std::nullopt);
CAF_IO_EXPORT expected<native_socket> CAF_IO_EXPORT expected<native_socket>
new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr); new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr);
expected<std::pair<native_socket, ip_endpoint>> expected<std::pair<native_socket, ip_endpoint>>
new_remote_udp_endpoint_impl(const std::string& host, uint16_t port, new_remote_udp_endpoint_impl(const std::string& host, uint16_t port,
optional<protocol::network> preferred = none); std::optional<protocol::network> preferred
= std::nullopt);
expected<std::pair<native_socket, protocol::network>> expected<std::pair<native_socket, protocol::network>>
new_local_udp_endpoint_impl(uint16_t port, const char* addr, new_local_udp_endpoint_impl(uint16_t port, const char* addr,
bool reuse_addr = false, bool reuse_addr = false,
optional<protocol::network> preferred = none); std::optional<protocol::network> preferred
= std::nullopt);
} // namespace caf::io::network } // namespace caf::io::network
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <functional> #include <functional>
#include <initializer_list> #include <initializer_list>
#include <map> #include <map>
#include <optional>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#include "caf/detail/io_export.hpp" #include "caf/detail/io_export.hpp"
#include "caf/io/network/ip_endpoint.hpp" #include "caf/io/network/ip_endpoint.hpp"
#include "caf/io/network/protocol.hpp" #include "caf/io/network/protocol.hpp"
#include "caf/optional.hpp"
namespace caf::io::network { namespace caf::io::network {
...@@ -49,23 +49,23 @@ public: ...@@ -49,23 +49,23 @@ public:
bool include_localhost = true); bool include_localhost = true);
/// Returns all addresses for all devices for given protocol. /// Returns all addresses for all devices for given protocol.
static std::vector<std::string> static std::vector<std::string> list_addresses(protocol::network proc,
list_addresses(protocol::network proc, bool include_localhost = true); bool include_localhost = true);
/// Returns a native IPv4 or IPv6 translation of `host`. /// Returns a native IPv4 or IPv6 translation of `host`.
static optional<std::pair<std::string, protocol::network>> static std::optional<std::pair<std::string, protocol::network>>
native_address(const std::string& host, native_address(const std::string& host,
optional<protocol::network> preferred = none); std::optional<protocol::network> preferred = std::nullopt);
/// Returns the host and protocol available for a local server socket /// Returns the host and protocol available for a local server socket
static std::vector<std::pair<std::string, protocol::network>> static std::vector<std::pair<std::string, protocol::network>>
server_address(uint16_t port, const char* host, server_address(uint16_t port, const char* host,
optional<protocol::network> preferred = none); std::optional<protocol::network> preferred = std::nullopt);
/// Writes datagram endpoint info for `host`:`port` into ep /// Writes datagram endpoint info for `host`:`port` into ep
static bool static bool
get_endpoint(const std::string& host, uint16_t port, ip_endpoint& ep, get_endpoint(const std::string& host, uint16_t port, ip_endpoint& ep,
optional<protocol::network> preferred = none); std::optional<protocol::network> preferred = std::nullopt);
}; };
} // namespace caf::io::network } // namespace caf::io::network
...@@ -85,7 +85,7 @@ void instance::handle_heartbeat(execution_unit* ctx) { ...@@ -85,7 +85,7 @@ void instance::handle_heartbeat(execution_unit* ctx) {
} }
} }
optional<routing_table::route> instance::lookup(const node_id& target) { std::optional<routing_table::route> instance::lookup(const node_id& target) {
return tbl_.lookup(target); return tbl_.lookup(target);
} }
...@@ -112,8 +112,8 @@ void instance::add_published_actor(uint16_t port, ...@@ -112,8 +112,8 @@ void instance::add_published_actor(uint16_t port,
swap(entry.second, published_interface); swap(entry.second, published_interface);
} }
size_t size_t instance::remove_published_actor(uint16_t port,
instance::remove_published_actor(uint16_t port, removed_published_actor* cb) { removed_published_actor* cb) {
CAF_LOG_TRACE(CAF_ARG(port)); CAF_LOG_TRACE(CAF_ARG(port));
auto i = published_actors_.find(port); auto i = published_actors_.find(port);
if (i == published_actors_.end()) if (i == published_actors_.end())
...@@ -223,7 +223,7 @@ void instance::write(execution_unit* ctx, byte_buffer& buf, header& hdr, ...@@ -223,7 +223,7 @@ void instance::write(execution_unit* ctx, byte_buffer& buf, header& hdr,
} }
void instance::write_server_handshake(execution_unit* ctx, byte_buffer& out_buf, void instance::write_server_handshake(execution_unit* ctx, byte_buffer& out_buf,
optional<uint16_t> port) { std::optional<uint16_t> port) {
CAF_LOG_TRACE(CAF_ARG(port)); CAF_LOG_TRACE(CAF_ARG(port));
using namespace detail; using namespace detail;
published_actor* pa = nullptr; published_actor* pa = nullptr;
......
...@@ -16,7 +16,8 @@ routing_table::~routing_table() { ...@@ -16,7 +16,8 @@ routing_table::~routing_table() {
// nop // nop
} }
optional<routing_table::route> routing_table::lookup(const node_id& target) { std::optional<routing_table::route>
routing_table::lookup(const node_id& target) {
std::unique_lock<std::mutex> guard{mtx_}; std::unique_lock<std::mutex> guard{mtx_};
// Check whether we have a direct path first. // Check whether we have a direct path first.
{ // Lifetime scope of first iterator. { // Lifetime scope of first iterator.
...@@ -37,7 +38,7 @@ optional<routing_table::route> routing_table::lookup(const node_id& target) { ...@@ -37,7 +38,7 @@ optional<routing_table::route> routing_table::lookup(const node_id& target) {
hops.erase(hops.begin()); hops.erase(hops.begin());
} }
} }
return none; return std::nullopt;
} }
node_id routing_table::lookup_direct(const connection_handle& hdl) const { node_id routing_table::lookup_direct(const connection_handle& hdl) const {
...@@ -48,13 +49,13 @@ node_id routing_table::lookup_direct(const connection_handle& hdl) const { ...@@ -48,13 +49,13 @@ node_id routing_table::lookup_direct(const connection_handle& hdl) const {
return {}; return {};
} }
optional<connection_handle> std::optional<connection_handle>
routing_table::lookup_direct(const node_id& nid) const { routing_table::lookup_direct(const node_id& nid) const {
std::unique_lock<std::mutex> guard{mtx_}; std::unique_lock<std::mutex> guard{mtx_};
auto i = direct_by_nid_.find(nid); auto i = direct_by_nid_.find(nid);
if (i != direct_by_nid_.end()) if (i != direct_by_nid_.end())
return i->second; return i->second;
return {}; return std::nullopt;
} }
node_id routing_table::lookup_indirect(const node_id& nid) const { node_id routing_table::lookup_indirect(const node_id& nid) const {
......
...@@ -191,7 +191,7 @@ behavior basp_broker::make_behavior() { ...@@ -191,7 +191,7 @@ behavior basp_broker::make_behavior() {
return; return;
} }
auto route = instance.tbl().lookup(proxy->node()); auto route = instance.tbl().lookup(proxy->node());
if (route == none) { if (!route) {
CAF_LOG_DEBUG("connection to origin already lost, kill proxy"); CAF_LOG_DEBUG("connection to origin already lost, kill proxy");
instance.proxies().erase(proxy->node(), proxy->id()); instance.proxies().erase(proxy->node(), proxy->id());
return; return;
...@@ -217,7 +217,7 @@ behavior basp_broker::make_behavior() { ...@@ -217,7 +217,7 @@ behavior basp_broker::make_behavior() {
} }
// Check whether the node is still connected at the moment and send the // Check whether the node is still connected at the moment and send the
// observer a message immediately otherwise. // observer a message immediately otherwise.
if (instance.tbl().lookup(node) == none) { if (!instance.tbl().lookup(node)) {
if (auto hdl = actor_cast<actor>(observer)) { if (auto hdl = actor_cast<actor>(observer)) {
// TODO: we might want to consider keeping the exit reason for nodes, // TODO: we might want to consider keeping the exit reason for nodes,
// at least for some time. Otherwise, we'll have to send a // at least for some time. Otherwise, we'll have to send a
...@@ -343,9 +343,8 @@ behavior basp_broker::make_behavior() { ...@@ -343,9 +343,8 @@ behavior basp_broker::make_behavior() {
}, },
[=](unpublish_atom, const actor_addr& whom, uint16_t port) -> result<void> { [=](unpublish_atom, const actor_addr& whom, uint16_t port) -> result<void> {
CAF_LOG_TRACE(CAF_ARG(whom) << CAF_ARG(port)); CAF_LOG_TRACE(CAF_ARG(whom) << CAF_ARG(port));
auto cb = make_callback([&](const strong_actor_ptr&, uint16_t x) { auto cb = make_callback(
close(hdl_by_port(x)); [&](const strong_actor_ptr&, uint16_t x) { close(hdl_by_port(x)); });
});
if (instance.remove_published_actor(whom, port, &cb) == 0) if (instance.remove_published_actor(whom, port, &cb) == 0)
return sec::no_actor_published_at_port; return sec::no_actor_published_at_port;
return unit; return unit;
...@@ -446,8 +445,9 @@ strong_actor_ptr basp_broker::make_proxy(node_id nid, actor_id aid) { ...@@ -446,8 +445,9 @@ strong_actor_ptr basp_broker::make_proxy(node_id nid, actor_id aid) {
// create proxy and add functor that will be called if we // create proxy and add functor that will be called if we
// receive a basp::down_message // receive a basp::down_message
actor_config cfg; actor_config cfg;
auto res = make_actor<forwarding_actor_proxy, strong_actor_ptr>( auto res = make_actor<forwarding_actor_proxy, strong_actor_ptr>(aid, nid,
aid, nid, &(system()), cfg, this); &(system()),
cfg, this);
strong_actor_ptr selfptr{ctrl()}; strong_actor_ptr selfptr{ctrl()};
res->get()->attach_functor([=](const error& rsn) { res->get()->attach_functor([=](const error& rsn) {
mm->backend().post([=] { mm->backend().post([=] {
...@@ -472,7 +472,7 @@ void basp_broker::finalize_handshake(const node_id& nid, actor_id aid, ...@@ -472,7 +472,7 @@ void basp_broker::finalize_handshake(const node_id& nid, actor_id aid,
CAF_ASSERT(this_context != nullptr); CAF_ASSERT(this_context != nullptr);
this_context->id = nid; this_context->id = nid;
auto& cb = this_context->callback; auto& cb = this_context->callback;
if (cb == none) if (!cb)
return; return;
strong_actor_ptr ptr; strong_actor_ptr ptr;
// aid can be invalid when connecting to the default port of a node // aid can be invalid when connecting to the default port of a node
...@@ -487,7 +487,7 @@ void basp_broker::finalize_handshake(const node_id& nid, actor_id aid, ...@@ -487,7 +487,7 @@ void basp_broker::finalize_handshake(const node_id& nid, actor_id aid,
} }
} }
cb->deliver(nid, std::move(ptr), std::move(sigs)); cb->deliver(nid, std::move(ptr), std::move(sigs));
cb = none; cb = std::nullopt;
} }
void basp_broker::purge_state(const node_id& nid) { void basp_broker::purge_state(const node_id& nid) {
......
...@@ -108,8 +108,8 @@ auto middleman_actor_impl::make_behavior() -> behavior_type { ...@@ -108,8 +108,8 @@ auto middleman_actor_impl::make_behavior() -> behavior_type {
monitor(addr); monitor(addr);
cached_tcp_.emplace(key, std::make_tuple(nid, addr, sigs)); cached_tcp_.emplace(key, std::make_tuple(nid, addr, sigs));
} }
auto res auto res = make_message(std::move(nid), std::move(addr),
= make_message(std::move(nid), std::move(addr), std::move(sigs)); std::move(sigs));
for (auto& promise : i->second) for (auto& promise : i->second)
promise.deliver(res); promise.deliver(res);
pending_.erase(i); pending_.erase(i);
...@@ -216,32 +216,32 @@ middleman_actor_impl::put_udp(uint16_t port, strong_actor_ptr& whom, ...@@ -216,32 +216,32 @@ middleman_actor_impl::put_udp(uint16_t port, strong_actor_ptr& whom,
return actual_port; return actual_port;
} }
optional<middleman_actor_impl::endpoint_data&> middleman_actor_impl::endpoint_data*
middleman_actor_impl::cached_tcp(const endpoint& ep) { middleman_actor_impl::cached_tcp(const endpoint& ep) {
auto i = cached_tcp_.find(ep); auto i = cached_tcp_.find(ep);
if (i != cached_tcp_.end()) if (i != cached_tcp_.end())
return i->second; return std::addressof(i->second);
return none; return nullptr;
} }
optional<middleman_actor_impl::endpoint_data&> middleman_actor_impl::endpoint_data*
middleman_actor_impl::cached_udp(const endpoint& ep) { middleman_actor_impl::cached_udp(const endpoint& ep) {
auto i = cached_udp_.find(ep); auto i = cached_udp_.find(ep);
if (i != cached_udp_.end()) if (i != cached_udp_.end())
return i->second; return std::addressof(i->second);
return none; return nullptr;
} }
optional<std::vector<response_promise>&> std::vector<response_promise>*
middleman_actor_impl::pending(const endpoint& ep) { middleman_actor_impl::pending(const endpoint& ep) {
auto i = pending_.find(ep); auto i = pending_.find(ep);
if (i != pending_.end()) if (i != pending_.end())
return i->second; return std::addressof(i->second);
return none; return nullptr;
} }
expected<scribe_ptr> expected<scribe_ptr> middleman_actor_impl::connect(const std::string& host,
middleman_actor_impl::connect(const std::string& host, uint16_t port) { uint16_t port) {
return system().middleman().backend().new_tcp_scribe(host, port); return system().middleman().backend().new_tcp_scribe(host, port);
} }
...@@ -250,8 +250,8 @@ middleman_actor_impl::contact(const std::string& host, uint16_t port) { ...@@ -250,8 +250,8 @@ middleman_actor_impl::contact(const std::string& host, uint16_t port) {
return system().middleman().backend().new_remote_udp_endpoint(host, port); return system().middleman().backend().new_remote_udp_endpoint(host, port);
} }
expected<doorman_ptr> expected<doorman_ptr> middleman_actor_impl::open(uint16_t port,
middleman_actor_impl::open(uint16_t port, const char* addr, bool reuse) { const char* addr, bool reuse) {
return system().middleman().backend().new_tcp_doorman(port, addr, reuse); return system().middleman().backend().new_tcp_doorman(port, addr, reuse);
} }
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
#include "caf/io/network/default_multiplexer.hpp" #include "caf/io/network/default_multiplexer.hpp"
#include <optional>
#include <utility> #include <utility>
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/defaults.hpp" #include "caf/defaults.hpp"
#include "caf/make_counted.hpp" #include "caf/make_counted.hpp"
#include "caf/optional.hpp"
#include "caf/io/broker.hpp" #include "caf/io/broker.hpp"
#include "caf/io/middleman.hpp" #include "caf/io/middleman.hpp"
...@@ -671,8 +671,8 @@ doorman_ptr default_multiplexer::new_doorman(native_socket fd) { ...@@ -671,8 +671,8 @@ doorman_ptr default_multiplexer::new_doorman(native_socket fd) {
return make_counted<doorman_impl>(*this, fd); return make_counted<doorman_impl>(*this, fd);
} }
expected<doorman_ptr> expected<doorman_ptr> default_multiplexer::new_tcp_doorman(uint16_t port,
default_multiplexer::new_tcp_doorman(uint16_t port, const char* in, const char* in,
bool reuse_addr) { bool reuse_addr) {
auto fd = new_tcp_acceptor_impl(port, in, reuse_addr); auto fd = new_tcp_acceptor_impl(port, in, reuse_addr);
if (fd) if (fd)
...@@ -745,7 +745,7 @@ bool ip_connect(native_socket fd, const std::string& host, uint16_t port) { ...@@ -745,7 +745,7 @@ bool ip_connect(native_socket fd, const std::string& host, uint16_t port) {
expected<native_socket> expected<native_socket>
new_tcp_connection(const std::string& host, uint16_t port, new_tcp_connection(const std::string& host, uint16_t port,
optional<protocol::network> preferred) { std::optional<protocol::network> preferred) {
CAF_LOG_TRACE(CAF_ARG(host) << CAF_ARG(port) << CAF_ARG(preferred)); CAF_LOG_TRACE(CAF_ARG(host) << CAF_ARG(port) << CAF_ARG(preferred));
CAF_LOG_DEBUG("try to connect to:" << CAF_ARG(host) << CAF_ARG(port)); CAF_LOG_DEBUG("try to connect to:" << CAF_ARG(host) << CAF_ARG(port));
auto res = interfaces::native_address(host, std::move(preferred)); auto res = interfaces::native_address(host, std::move(preferred));
...@@ -844,8 +844,8 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr, ...@@ -844,8 +844,8 @@ expected<native_socket> new_ip_acceptor_impl(uint16_t port, const char* addr,
return sguard.release(); return sguard.release();
} }
expected<native_socket> expected<native_socket> new_tcp_acceptor_impl(uint16_t port, const char* addr,
new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr) { bool reuse_addr) {
CAF_LOG_TRACE(CAF_ARG(port) << ", addr = " << (addr ? addr : "nullptr")); CAF_LOG_TRACE(CAF_ARG(port) << ", addr = " << (addr ? addr : "nullptr"));
auto addrs = interfaces::server_address(port, addr); auto addrs = interfaces::server_address(port, addr);
auto addr_str = std::string{addr == nullptr ? "" : addr}; auto addr_str = std::string{addr == nullptr ? "" : addr};
...@@ -856,10 +856,10 @@ new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr) { ...@@ -856,10 +856,10 @@ new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr) {
auto fd = invalid_native_socket; auto fd = invalid_native_socket;
for (auto& elem : addrs) { for (auto& elem : addrs) {
auto hostname = elem.first.c_str(); auto hostname = elem.first.c_str();
auto p auto p = elem.second == ipv4
= elem.second == ipv4
? new_ip_acceptor_impl<AF_INET>(port, hostname, reuse_addr, any) ? new_ip_acceptor_impl<AF_INET>(port, hostname, reuse_addr, any)
: new_ip_acceptor_impl<AF_INET6>(port, hostname, reuse_addr, any); : new_ip_acceptor_impl<AF_INET6>(port, hostname, reuse_addr,
any);
if (!p) { if (!p) {
CAF_LOG_DEBUG(p.error()); CAF_LOG_DEBUG(p.error());
continue; continue;
...@@ -882,7 +882,7 @@ new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr) { ...@@ -882,7 +882,7 @@ new_tcp_acceptor_impl(uint16_t port, const char* addr, bool reuse_addr) {
expected<std::pair<native_socket, ip_endpoint>> expected<std::pair<native_socket, ip_endpoint>>
new_remote_udp_endpoint_impl(const std::string& host, uint16_t port, new_remote_udp_endpoint_impl(const std::string& host, uint16_t port,
optional<protocol::network> preferred) { std::optional<protocol::network> preferred) {
CAF_LOG_TRACE(CAF_ARG(host) << CAF_ARG(port) << CAF_ARG(preferred)); CAF_LOG_TRACE(CAF_ARG(host) << CAF_ARG(port) << CAF_ARG(preferred));
auto lep = new_local_udp_endpoint_impl(0, nullptr, false, preferred); auto lep = new_local_udp_endpoint_impl(0, nullptr, false, preferred);
if (!lep) if (!lep)
...@@ -898,7 +898,7 @@ new_remote_udp_endpoint_impl(const std::string& host, uint16_t port, ...@@ -898,7 +898,7 @@ new_remote_udp_endpoint_impl(const std::string& host, uint16_t port,
expected<std::pair<native_socket, protocol::network>> expected<std::pair<native_socket, protocol::network>>
new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse, new_local_udp_endpoint_impl(uint16_t port, const char* addr, bool reuse,
optional<protocol::network> preferred) { std::optional<protocol::network> preferred) {
CAF_LOG_TRACE(CAF_ARG(port) << ", addr = " << (addr ? addr : "nullptr")); CAF_LOG_TRACE(CAF_ARG(port) << ", addr = " << (addr ? addr : "nullptr"));
auto addrs = interfaces::server_address(port, addr, preferred); auto addrs = interfaces::server_address(port, addr, preferred);
auto addr_str = std::string{addr == nullptr ? "" : addr}; auto addr_str = std::string{addr == nullptr ? "" : addr};
......
...@@ -197,14 +197,14 @@ interfaces::list_addresses(std::initializer_list<protocol::network> procs, ...@@ -197,14 +197,14 @@ interfaces::list_addresses(std::initializer_list<protocol::network> procs,
return result; return result;
} }
std::vector<std::string> std::vector<std::string> interfaces::list_addresses(protocol::network proc,
interfaces::list_addresses(protocol::network proc, bool include_localhost) { bool include_localhost) {
return list_addresses({proc}, include_localhost); return list_addresses({proc}, include_localhost);
} }
optional<std::pair<std::string, protocol::network>> std::optional<std::pair<std::string, protocol::network>>
interfaces::native_address(const std::string& host, interfaces::native_address(const std::string& host,
optional<protocol::network> preferred) { std::optional<protocol::network> preferred) {
addrinfo hint; addrinfo hint;
memset(&hint, 0, sizeof(hint)); memset(&hint, 0, sizeof(hint));
hint.ai_socktype = SOCK_STREAM; hint.ai_socktype = SOCK_STREAM;
...@@ -212,7 +212,7 @@ interfaces::native_address(const std::string& host, ...@@ -212,7 +212,7 @@ interfaces::native_address(const std::string& host,
hint.ai_family = *preferred == protocol::ipv4 ? AF_INET : AF_INET6; hint.ai_family = *preferred == protocol::ipv4 ? AF_INET : AF_INET6;
addrinfo* tmp = nullptr; addrinfo* tmp = nullptr;
if (getaddrinfo(host.c_str(), nullptr, &hint, &tmp) != 0) if (getaddrinfo(host.c_str(), nullptr, &hint, &tmp) != 0)
return none; return std::nullopt;
std::unique_ptr<addrinfo, decltype(freeaddrinfo)*> addrs{tmp, freeaddrinfo}; std::unique_ptr<addrinfo, decltype(freeaddrinfo)*> addrs{tmp, freeaddrinfo};
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
for (auto i = addrs.get(); i != nullptr; i = i->ai_next) { for (auto i = addrs.get(); i != nullptr; i = i->ai_next) {
...@@ -221,12 +221,12 @@ interfaces::native_address(const std::string& host, ...@@ -221,12 +221,12 @@ interfaces::native_address(const std::string& host,
return std::make_pair(buffer, family == AF_INET ? protocol::ipv4 return std::make_pair(buffer, family == AF_INET ? protocol::ipv4
: protocol::ipv6); : protocol::ipv6);
} }
return none; return std::nullopt;
} }
std::vector<std::pair<std::string, protocol::network>> std::vector<std::pair<std::string, protocol::network>>
interfaces::server_address(uint16_t port, const char* host, interfaces::server_address(uint16_t port, const char* host,
optional<protocol::network> preferred) { std::optional<protocol::network> preferred) {
using addr_pair = std::pair<std::string, protocol::network>; using addr_pair = std::pair<std::string, protocol::network>;
addrinfo hint; addrinfo hint;
memset(&hint, 0, sizeof(hint)); memset(&hint, 0, sizeof(hint));
...@@ -261,7 +261,7 @@ interfaces::server_address(uint16_t port, const char* host, ...@@ -261,7 +261,7 @@ interfaces::server_address(uint16_t port, const char* host,
bool interfaces::get_endpoint(const std::string& host, uint16_t port, bool interfaces::get_endpoint(const std::string& host, uint16_t port,
ip_endpoint& ep, ip_endpoint& ep,
optional<protocol::network> preferred) { std::optional<protocol::network> preferred) {
static_assert(sizeof(uint16_t) == sizeof(unsigned short int), static_assert(sizeof(uint16_t) == sizeof(unsigned short int),
"uint16_t cannot be printed with %hu in snprintf"); "uint16_t cannot be printed with %hu in snprintf");
addrinfo hint; addrinfo hint;
......
...@@ -43,7 +43,7 @@ struct maybe { ...@@ -43,7 +43,7 @@ struct maybe {
// nop // nop
} }
caf::optional<T> val; std::optional<T> val;
}; };
template <class T> template <class T>
...@@ -241,7 +241,7 @@ public: ...@@ -241,7 +241,7 @@ public:
return {hdr, std::move(payload)}; return {hdr, std::move(payload)};
} }
void connect_node(node& n, optional<accept_handle> ax = none, void connect_node(node& n, std::optional<accept_handle> ax = std::nullopt,
actor_id published_actor_id = invalid_actor_id, actor_id published_actor_id = invalid_actor_id,
const std::set<std::string>& published_actor_ifs = {}) { const std::set<std::string>& published_actor_ifs = {}) {
auto src = ax ? *ax : ahdl_; auto src = ax ? *ax : ahdl_;
...@@ -436,7 +436,7 @@ CAF_TEST(empty_server_handshake) { ...@@ -436,7 +436,7 @@ CAF_TEST(empty_server_handshake) {
// test whether basp instance correctly sends a // test whether basp instance correctly sends a
// server handshake when there's no actor published // server handshake when there's no actor published
byte_buffer buf; byte_buffer buf;
instance().write_server_handshake(mpx(), buf, none); instance().write_server_handshake(mpx(), buf, std::nullopt);
basp::header hdr; basp::header hdr;
byte_buffer payload; byte_buffer payload;
std::tie(hdr, payload) = from_buf(buf); std::tie(hdr, payload) = from_buf(buf);
......
...@@ -216,21 +216,21 @@ private: ...@@ -216,21 +216,21 @@ private:
/// @private /// @private
template <class... Ts> template <class... Ts>
caf::optional<std::tuple<Ts...>> default_extract(caf_handle x) { std::optional<std::tuple<Ts...>> default_extract(caf_handle x) {
auto ptr = x->peek_at_next_mailbox_element(); auto ptr = x->peek_at_next_mailbox_element();
if (ptr == nullptr) if (ptr == nullptr)
return caf::none; return std::nullopt;
if (auto view = caf::make_const_typed_message_view<Ts...>(ptr->content())) if (auto view = caf::make_const_typed_message_view<Ts...>(ptr->content()))
return to_tuple(view); return to_tuple(view);
return caf::none; return std::nullopt;
} }
/// @private /// @private
template <class T> template <class T>
caf::optional<std::tuple<T>> unboxing_extract(caf_handle x) { std::optional<std::tuple<T>> unboxing_extract(caf_handle x) {
auto tup = default_extract<typename T::outer_type>(x); auto tup = default_extract<typename T::outer_type>(x);
if (tup == caf::none || !is<T>(get<0>(*tup))) if (!tup || !is<T>(get<0>(*tup)))
return caf::none; return std::nullopt;
return std::make_tuple(get<T>(get<0>(*tup))); return std::make_tuple(get<T>(get<0>(*tup)));
} }
...@@ -240,22 +240,22 @@ caf::optional<std::tuple<T>> unboxing_extract(caf_handle x) { ...@@ -240,22 +240,22 @@ caf::optional<std::tuple<T>> unboxing_extract(caf_handle x) {
/// @private /// @private
template <class T, bool HasOuterType, class... Ts> template <class T, bool HasOuterType, class... Ts>
struct try_extract_impl { struct try_extract_impl {
caf::optional<std::tuple<T, Ts...>> operator()(caf_handle x) { std::optional<std::tuple<T, Ts...>> operator()(caf_handle x) {
return default_extract<T, Ts...>(x); return default_extract<T, Ts...>(x);
} }
}; };
template <class T> template <class T>
struct try_extract_impl<T, true> { struct try_extract_impl<T, true> {
caf::optional<std::tuple<T>> operator()(caf_handle x) { std::optional<std::tuple<T>> operator()(caf_handle x) {
return unboxing_extract<T>(x); return unboxing_extract<T>(x);
} }
}; };
/// Returns the content of the next mailbox element as `tuple<T, Ts...>` on a /// Returns the content of the next mailbox element as `tuple<T, Ts...>` on a
/// match. Returns `none` otherwise. /// match. Returns `std::nullopt` otherwise.
template <class T, class... Ts> template <class T, class... Ts>
caf::optional<std::tuple<T, Ts...>> try_extract(caf_handle x) { std::optional<std::tuple<T, Ts...>> try_extract(caf_handle x) {
try_extract_impl<T, has_outer_type<T>::value, Ts...> f; try_extract_impl<T, has_outer_type<T>::value, Ts...> f;
return f(x); return f(x);
} }
...@@ -266,7 +266,7 @@ caf::optional<std::tuple<T, Ts...>> try_extract(caf_handle x) { ...@@ -266,7 +266,7 @@ caf::optional<std::tuple<T, Ts...>> try_extract(caf_handle x) {
template <class T, class... Ts> template <class T, class... Ts>
std::tuple<T, Ts...> extract(caf_handle x) { std::tuple<T, Ts...> extract(caf_handle x) {
auto result = try_extract<T, Ts...>(x); auto result = try_extract<T, Ts...>(x);
if (result == caf::none) { if (!result) {
auto ptr = x->peek_at_next_mailbox_element(); auto ptr = x->peek_at_next_mailbox_element();
if (ptr == nullptr) if (ptr == nullptr)
CAF_FAIL("Mailbox is empty"); CAF_FAIL("Mailbox is empty");
...@@ -278,7 +278,7 @@ std::tuple<T, Ts...> extract(caf_handle x) { ...@@ -278,7 +278,7 @@ std::tuple<T, Ts...> extract(caf_handle x) {
template <class T, class... Ts> template <class T, class... Ts>
bool received(caf_handle x) { bool received(caf_handle x) {
return try_extract<T, Ts...>(x) != caf::none; return try_extract<T, Ts...>(x) != std::nullopt;
} }
template <class... Ts> template <class... Ts>
...@@ -486,7 +486,7 @@ public: ...@@ -486,7 +486,7 @@ public:
: sched_(sched), dest_(nullptr) { : sched_(sched), dest_(nullptr) {
peek_ = [=] { peek_ = [=] {
if (dest_ != nullptr) if (dest_ != nullptr)
return try_extract<Ts...>(dest_) != caf::none; return try_extract<Ts...>(dest_) != std::nullopt;
return false; return false;
}; };
} }
...@@ -524,7 +524,7 @@ public: ...@@ -524,7 +524,7 @@ public:
using namespace caf::detail; using namespace caf::detail;
elementwise_compare_inspector<decltype(tmp)> inspector{tmp}; elementwise_compare_inspector<decltype(tmp)> inspector{tmp};
auto ys = try_extract<Ts...>(dest_); auto ys = try_extract<Ts...>(dest_);
if (ys != caf::none) { if (ys != std::nullopt) {
auto ys_indices = get_indices(*ys); auto ys_indices = get_indices(*ys);
return apply_args(inspector, ys_indices, *ys); return apply_args(inspector, ys_indices, *ys);
} }
...@@ -568,7 +568,7 @@ public: ...@@ -568,7 +568,7 @@ public:
if (src_ != nullptr && ptr->sender != src_) if (src_ != nullptr && ptr->sender != src_)
return; return;
auto res = try_extract<Ts...>(dest_); auto res = try_extract<Ts...>(dest_);
if (res != caf::none) if (res != std::nullopt)
CAF_FAIL("received disallowed message: " << caf::deep_to_string(*ptr)); CAF_FAIL("received disallowed message: " << caf::deep_to_string(*ptr));
}; };
} }
...@@ -607,7 +607,7 @@ public: ...@@ -607,7 +607,7 @@ public:
if (src_ != nullptr && ptr->sender != src_) if (src_ != nullptr && ptr->sender != src_)
return; return;
auto res = try_extract<Ts...>(dest_); auto res = try_extract<Ts...>(dest_);
if (res != caf::none) { if (res != std::nullopt) {
using namespace caf::detail; using namespace caf::detail;
elementwise_compare_inspector<decltype(tmp)> inspector{tmp}; elementwise_compare_inspector<decltype(tmp)> inspector{tmp};
auto& ys = *res; auto& ys = *res;
...@@ -873,9 +873,9 @@ T unbox(caf::expected<T> x) { ...@@ -873,9 +873,9 @@ T unbox(caf::expected<T> x) {
/// Unboxes an optional value or fails the test if it doesn't exist. /// Unboxes an optional value or fails the test if it doesn't exist.
template <class T> template <class T>
T unbox(caf::optional<T> x) { T unbox(std::optional<T> x) {
if (!x) if (!x)
CAF_FAIL("x == none"); CAF_FAIL("x == std::nullopt");
return std::move(*x); return std::move(*x);
} }
......
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