Commit 35aea2c1 authored by Dominik Charousset's avatar Dominik Charousset

Merge branch issue/1236-old into issue/1236

parents 11a1b0f9 782334e7
......@@ -37,13 +37,13 @@ macro(write_enum_file)
# File header and includes.
list(APPEND out
"#include \"caf/config.hpp\"\n"
"#include \"caf/string_view.hpp\"\n"
"\n"
"CAF_PUSH_DEPRECATED_WARNING\n"
"\n"
"#include \"${namespace_path}/${enum_name}.hpp\"\n"
"\n"
"#include <string>\n"
"#include <string_view>\n"
"\n"
"namespace ${namespace_str} {\n"
"\n")
......@@ -64,7 +64,7 @@ macro(write_enum_file)
"\n")
# Generate from_string implementation.
list(APPEND out
"bool from_string(string_view in, ${enum_name}& out) {\n")
"bool from_string(std::string_view in, ${enum_name}& out) {\n")
foreach(label IN LISTS enum_values)
list(APPEND out
" if (in == \"${namespace_str}::${enum_name}::${label}\") {\n"
......
......@@ -20,7 +20,7 @@ std::string to_string(math_error x) {
}
}
bool from_string(caf::string_view in, math_error& out) {
bool from_string(std::string_view in, math_error& out) {
if (in == "division_by_zero") {
out = math_error::division_by_zero;
return true;
......
......@@ -30,7 +30,7 @@ std::string to_string(fixed_stack_errc x) {
}
}
bool from_string(caf::string_view in, fixed_stack_errc& out) {
bool from_string(std::string_view in, fixed_stack_errc& out) {
if (in == "push_to_full") {
out = fixed_stack_errc::push_to_full;
return true;
......
#include <string>
#include <string_view>
#include <utility>
#include "caf/all.hpp"
......@@ -74,7 +75,7 @@ void ChatWidget::sendChatMessage() {
} else if (line.startsWith('/')) {
vector<string> words;
auto utf8 = QStringView{line}.mid(1).toUtf8();
auto sv = caf::string_view{utf8.constData(),
auto sv = std::string_view{utf8.constData(),
static_cast<size_t>(utf8.size())};
split(words, sv, is_any_of(" "));
if (words.size() == 3 && words[0] == "join") {
......
......@@ -195,12 +195,12 @@ string trim(std::string s) {
}
// tries to convert `str` to an int
optional<int> toint(const string& str) {
std::optional<int> toint(const string& str) {
char* end;
auto result = static_cast<int>(strtol(str.c_str(), &end, 10));
if (end == str.c_str() + str.size())
return result;
return none;
return std::nullopt;
}
// --(rst-config-begin)--
......
......@@ -81,12 +81,12 @@ void client_repl(function_view<calculator> f) {
usage();
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;
auto res = strtol(str.c_str(), &end, 10);
if (end == str.c_str() + str.size())
return static_cast<int32_t>(res);
return none;
return std::nullopt;
};
auto x = to_int32_t(words[0]);
auto y = to_int32_t(words[2]);
......
......@@ -228,7 +228,6 @@ caf_add_component(
binary_deserializer
binary_serializer
blocking_actor
byte
composition
config_option
config_option_set
......
......@@ -64,8 +64,8 @@ struct typed_mpi_access<result<Out...>(In...)> {
std::string operator()() const {
static_assert(sizeof...(In) > 0, "typed MPI without inputs");
static_assert(sizeof...(Out) > 0, "typed MPI without outputs");
std::vector<std::string> inputs{to_string(type_name_v<In>)...};
std::vector<std::string> outputs1{to_string(type_name_v<Out>)...};
std::vector<std::string> inputs{std::string{type_name_v<In>}...};
std::vector<std::string> outputs1{std::string{type_name_v<Out>}...};
std::string result = "(";
result += join(inputs, ",");
result += ") -> (";
......@@ -85,8 +85,8 @@ std::string get_rtti_from_mpi() {
namespace caf {
/// Actor environment including scheduler, registry, and optional components
/// such as a middleman.
/// Actor environment including scheduler, registry, and optional
/// components such as a middleman.
class CAF_CORE_EXPORT actor_system {
public:
friend class logger;
......@@ -146,7 +146,8 @@ public:
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 {
public:
~networking_module() override;
......@@ -744,7 +745,7 @@ private:
expected<strong_actor_ptr>
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.
void spawn_serv(strong_actor_ptr x) {
......
......@@ -8,6 +8,7 @@
#include <functional>
#include <memory>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
......@@ -83,7 +84,7 @@ public:
/// Sets a config by using its name `config_name` to `config_value`.
template <class T>
actor_system_config& set(string_view name, T&& value) {
actor_system_config& set(std::string_view name, T&& value) {
return set_impl(name, config_value{std::forward<T>(value)});
}
......@@ -308,7 +309,7 @@ private:
mutable std::vector<char*> c_args_remainder_;
std::vector<char> c_args_remainder_buf_;
actor_system_config& set_impl(string_view name, config_value value);
actor_system_config& set_impl(std::string_view name, config_value value);
std::pair<error, std::string> extract_config_file_path(string_list& args);
};
......@@ -319,28 +320,28 @@ CAF_CORE_EXPORT const settings& content(const actor_system_config& cfg);
/// Returns whether `xs` associates a value of type `T` to `name`.
/// @relates actor_system_config
template <class T>
bool holds_alternative(const actor_system_config& cfg, string_view name) {
bool holds_alternative(const actor_system_config& cfg, std::string_view name) {
return holds_alternative<T>(content(cfg), name);
}
/// Tries to retrieve the value associated to `name` from `cfg`.
/// @relates actor_system_config
template <class T>
auto get_if(const actor_system_config* cfg, string_view name) {
auto get_if(const actor_system_config* cfg, std::string_view name) {
return get_if<T>(&content(*cfg), name);
}
/// Retrieves the value associated to `name` from `cfg`.
/// @relates actor_system_config
template <class T>
T get(const actor_system_config& cfg, string_view name) {
T get(const actor_system_config& cfg, std::string_view name) {
return get<T>(content(cfg), name);
}
/// Retrieves the value associated to `name` from `cfg` or returns `fallback`.
/// @relates actor_system_config
template <class To = get_or_auto_deduce, class Fallback>
auto get_or(const actor_system_config& cfg, string_view name,
auto get_or(const actor_system_config& cfg, std::string_view name,
Fallback&& fallback) {
return get_or<To>(content(cfg), name, std::forward<Fallback>(fallback));
}
......@@ -349,7 +350,7 @@ auto get_or(const actor_system_config& cfg, string_view name,
/// of type `T`.
/// @relates actor_system_config
template <class T>
expected<T> get_as(const actor_system_config& cfg, string_view name) {
expected<T> get_as(const actor_system_config& cfg, std::string_view name) {
return get_as<T>(content(cfg), name);
}
......
......@@ -25,6 +25,7 @@
#include "caf/binary_deserializer.hpp"
#include "caf/binary_serializer.hpp"
#include "caf/blocking_actor.hpp"
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/byte_span.hpp"
#include "caf/caf_main.hpp"
......@@ -59,6 +60,7 @@
#include "caf/message_priority.hpp"
#include "caf/mtl.hpp"
#include "caf/node_id.hpp"
#include "caf/optional.hpp"
#include "caf/others.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/raise_error.hpp"
......@@ -75,6 +77,7 @@
#include "caf/skip.hpp"
#include "caf/spawn_options.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/string_view.hpp"
#include "caf/system_messages.hpp"
#include "caf/term.hpp"
#include "caf/thread_hook.hpp"
......
......@@ -11,7 +11,6 @@
#include <memory>
#include "caf/async/fwd.hpp"
#include "caf/byte.hpp"
#include "caf/config.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
......@@ -40,7 +39,7 @@ public:
template <class T>
friend batch make_batch(span<const T> items);
using item_destructor = void (*)(type_id_t, uint16_t, size_t, byte*);
using item_destructor = void (*)(type_id_t, uint16_t, size_t, std::byte*);
batch() = default;
batch(batch&&) = default;
......@@ -143,11 +142,11 @@ private:
return size_;
}
byte* storage() noexcept {
std::byte* storage() noexcept {
return storage_;
}
const byte* storage() const noexcept {
const std::byte* storage() const noexcept {
return storage_;
}
......@@ -176,7 +175,7 @@ private:
type_id_t item_type_;
uint16_t item_size_;
size_t size_;
byte storage_[];
std::byte storage_[];
};
explicit batch(intrusive_ptr<data> ptr) : data_(std::move(ptr)) {
......@@ -205,7 +204,8 @@ batch make_batch(span<const T> items) {
auto vptr = malloc(total_size);
if (vptr == nullptr)
CAF_RAISE_ERROR(std::bad_alloc, "make_batch");
auto destroy_items = [](type_id_t, uint16_t, size_t size, byte* storage) {
auto destroy_items = [](type_id_t, uint16_t, size_t size,
std::byte* storage) {
auto ptr = reinterpret_cast<T*>(storage);
std::destroy(ptr, ptr + size);
};
......
......@@ -7,6 +7,7 @@
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/core_export.hpp"
#include <string_view>
#include <type_traits>
namespace caf::async {
......@@ -27,7 +28,7 @@ enum class read_result {
CAF_CORE_EXPORT std::string to_string(read_result);
/// @relates read_result
CAF_CORE_EXPORT bool from_string(string_view, read_result&);
CAF_CORE_EXPORT bool from_string(std::string_view, read_result&);
/// @relates read_result
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<read_result>,
......
......@@ -7,6 +7,7 @@
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/core_export.hpp"
#include <string_view>
#include <type_traits>
namespace caf::async {
......@@ -28,7 +29,7 @@ enum class write_result {
CAF_CORE_EXPORT std::string to_string(write_result);
/// @relates write_result
CAF_CORE_EXPORT bool from_string(string_view, write_result&);
CAF_CORE_EXPORT bool from_string(std::string_view, write_result&);
/// @relates write_result
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<write_result>,
......
// Deprecated include. The next CAF release won't include this header.
......@@ -12,7 +12,6 @@
#include "caf/error.hpp"
#include "caf/execution_unit.hpp"
#include "caf/exit_reason.hpp"
#include "caf/optional.hpp"
namespace caf {
......
......@@ -86,8 +86,8 @@ public:
}
/// Runs this handler and returns its (optional) result.
optional<message> operator()(message& xs) {
return impl_ ? impl_->invoke(xs) : none;
std::optional<message> operator()(message& xs) {
return impl_ ? impl_->invoke(xs) : std::nullopt;
}
/// Runs this handler with callback.
......
......@@ -6,6 +6,7 @@
#include <cstddef>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
......@@ -17,12 +18,11 @@
#include "caf/load_inspector_base.hpp"
#include "caf/sec.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
namespace caf {
/// Deserializes C++ objects from sequence of bytes. Does not perform run-time
/// type checks.
/// Deserializes C++ objects from sequence of bytes. Does not perform
/// run-time type checks.
class CAF_CORE_EXPORT binary_deserializer
: public load_inspector_base<binary_deserializer> {
public:
......@@ -46,14 +46,14 @@ public:
binary_deserializer(execution_unit* ctx, const void* buf,
size_t size) noexcept
: binary_deserializer(ctx,
make_span(reinterpret_cast<const byte*>(buf), size)) {
: binary_deserializer(
ctx, make_span(reinterpret_cast<const std::byte*>(buf), size)) {
// nop
}
binary_deserializer(actor_system& sys, const void* buf, size_t size) noexcept
: binary_deserializer(sys,
make_span(reinterpret_cast<const byte*>(buf), size)) {
: binary_deserializer(
sys, make_span(reinterpret_cast<const std::byte*>(buf), size)) {
// nop
}
......@@ -65,7 +65,7 @@ public:
}
/// Returns the remaining bytes.
span<const byte> remainder() const noexcept {
span<const std::byte> remainder() const noexcept {
return make_span(current_, end_);
}
......@@ -79,15 +79,15 @@ public:
void skip(size_t num_bytes);
/// Assigns a new input.
void reset(span<const byte> bytes) noexcept;
void reset(span<const std::byte> bytes) noexcept;
/// Returns the current read position.
const byte* current() const noexcept {
const std::byte* current() const noexcept {
return current_;
}
/// Returns the end of the assigned memory block.
const byte* end() const noexcept {
const std::byte* end() const noexcept {
return end_;
}
......@@ -99,7 +99,7 @@ public:
bool fetch_next_object_type(type_id_t& type) noexcept;
constexpr bool begin_object(type_id_t, string_view) noexcept {
constexpr bool begin_object(type_id_t, std::string_view) noexcept {
return true;
}
......@@ -107,16 +107,16 @@ public:
return true;
}
constexpr bool begin_field(string_view) noexcept {
constexpr bool begin_field(std::string_view) noexcept {
return true;
}
bool begin_field(string_view name, bool& is_present) noexcept;
bool begin_field(std::string_view name, bool& is_present) noexcept;
bool begin_field(string_view name, span<const type_id_t> types,
bool begin_field(std::string_view name, span<const type_id_t> types,
size_t& index) noexcept;
bool begin_field(string_view name, bool& is_present,
bool begin_field(std::string_view name, bool& is_present,
span<const type_id_t> types, size_t& index) noexcept;
constexpr bool end_field() {
......@@ -155,7 +155,7 @@ public:
bool value(bool& x) noexcept;
bool value(byte& x) noexcept;
bool value(std::byte& x) noexcept;
bool value(uint8_t& x) noexcept;
......@@ -196,7 +196,7 @@ public:
bool value(std::u32string& x);
bool value(span<byte> x) noexcept;
bool value(span<std::byte> x) noexcept;
bool value(std::vector<bool>& x);
......@@ -209,10 +209,10 @@ private:
}
/// Points to the current read position.
const byte* current_;
const std::byte* current_;
/// Points to the end of the assigned memory block.
const byte* end_;
const std::byte* end_;
/// Provides access to the ::proxy_registry and to the ::actor_system.
execution_unit* context_;
......
......@@ -9,7 +9,6 @@
#include <type_traits>
#include <vector>
#include "caf/byte.hpp"
#include "caf/byte_buffer.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/squashed_int.hpp"
......@@ -32,7 +31,7 @@ public:
using container_type = byte_buffer;
using value_type = byte;
using value_type = std::byte;
// -- constructors, destructors, and assignment operators --------------------
......@@ -84,7 +83,7 @@ public:
// -- interface functions ----------------------------------------------------
constexpr bool begin_object(type_id_t, string_view) noexcept {
constexpr bool begin_object(type_id_t, std::string_view) noexcept {
return true;
}
......@@ -92,16 +91,16 @@ public:
return true;
}
constexpr bool begin_field(string_view) noexcept {
constexpr bool begin_field(std::string_view) noexcept {
return true;
}
bool begin_field(string_view, bool is_present);
bool begin_field(std::string_view, bool is_present);
bool begin_field(string_view, span<const type_id_t> types, size_t index);
bool begin_field(std::string_view, span<const type_id_t> types, size_t index);
bool begin_field(string_view, bool is_present, span<const type_id_t> types,
size_t index);
bool begin_field(std::string_view, bool is_present,
span<const type_id_t> types, size_t index);
constexpr bool end_field() {
return true;
......@@ -137,7 +136,7 @@ public:
return end_sequence();
}
bool value(byte x);
bool value(std::byte x);
bool value(bool x);
......@@ -168,13 +167,13 @@ public:
bool value(long double x);
bool value(string_view x);
bool value(std::string_view x);
bool value(const std::u16string& x);
bool value(const std::u32string& x);
bool value(span<const byte> x);
bool value(span<const std::byte> x);
bool value(const std::vector<bool>& x);
......
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
// Deprecated include. The next CAF release won't include this header.
#include <cstdint>
#include <cstddef>
#include <type_traits>
#pragma once
namespace caf {
/// A C++11/14 drop-in replacement for C++17's `std::byte`.
enum class byte : uint8_t {};
template <class IntegerType,
class = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr IntegerType to_integer(byte x) noexcept {
[[deprecated("use std::to_integer instead")]] constexpr IntegerType
to_integer(std::byte x) noexcept {
return static_cast<IntegerType>(x);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte& operator<<=(byte& x, IntegerType shift) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) << shift);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte operator<<(byte x, IntegerType shift) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) << shift);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte& operator>>=(byte& x, IntegerType shift) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) >> shift);
}
template <class IntegerType,
class E = std::enable_if_t<std::is_integral<IntegerType>::value>>
constexpr byte operator>>(byte x, IntegerType shift) noexcept {
return static_cast<byte>(static_cast<unsigned char>(x) >> shift);
}
inline byte& operator|=(byte& x, byte y) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) | to_integer<uint8_t>(y));
}
constexpr byte operator|(byte x, byte y) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) | to_integer<uint8_t>(y));
}
inline byte& operator&=(byte& x, byte y) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) & to_integer<uint8_t>(y));
}
constexpr byte operator&(byte x, byte y) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) & to_integer<uint8_t>(y));
}
inline byte& operator^=(byte& x, byte y) noexcept {
return x = static_cast<byte>(to_integer<uint8_t>(x) ^ to_integer<uint8_t>(y));
}
constexpr byte operator^(byte x, byte y) noexcept {
return static_cast<byte>(to_integer<uint8_t>(x) ^ to_integer<uint8_t>(y));
}
constexpr byte operator~(byte x) noexcept {
return static_cast<byte>(~to_integer<uint8_t>(x));
}
} // namespace caf
......@@ -4,13 +4,12 @@
#pragma once
#include <cstddef>
#include <vector>
#include "caf/byte.hpp"
namespace caf {
/// A buffer for storing binary data.
using byte_buffer = std::vector<byte>;
using byte_buffer = std::vector<std::byte>;
} // namespace caf
......@@ -4,15 +4,16 @@
#pragma once
#include "caf/byte.hpp"
#include <cstddef>
#include "caf/span.hpp"
namespace caf {
/// Convenience alias for referring to a writable sequence of bytes.
using byte_span = span<byte>;
using byte_span = span<std::byte>;
/// Convenience alias for referring to a read-only sequence of bytes.
using const_byte_span = span<const byte>;
using const_byte_span = span<const std::byte>;
} // namespace caf
......@@ -5,12 +5,13 @@
#pragma once
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
#include "caf/string_algorithms.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -34,14 +35,15 @@ public:
config_value (*get)(const void*);
/// Human-readable name of the option's type.
string_view type_name;
std::string_view type_name;
};
// -- constructors, destructors, and assignment operators --------------------
/// Constructs a config option.
config_option(string_view category, string_view name, string_view description,
const meta_state* meta, void* value = nullptr);
config_option(std::string_view category, std::string_view name,
std::string_view description, const meta_state* meta,
void* value = nullptr);
config_option(const config_option&);
......@@ -58,19 +60,19 @@ public:
// -- properties -------------------------------------------------------------
/// Returns the category of the option.
string_view category() const noexcept;
std::string_view category() const noexcept;
/// Returns the name of the option.
string_view long_name() const noexcept;
std::string_view long_name() const noexcept;
/// Returns (optional) one-letter short names of the option.
string_view short_names() const noexcept;
std::string_view short_names() const noexcept;
/// Returns a human-readable description of the option.
string_view description() const noexcept;
std::string_view description() const noexcept;
/// Returns the full name for this config option as "<category>.<long name>".
string_view full_name() const noexcept;
std::string_view full_name() const noexcept;
/// Synchronizes the value of this config option with `x` and vice versa.
///
......@@ -82,7 +84,7 @@ public:
error sync(config_value& x) const;
/// Returns a human-readable representation of this option's expected type.
string_view type_name() const noexcept;
std::string_view type_name() const noexcept;
/// Returns whether this config option stores a boolean flag.
bool is_flag() const noexcept;
......@@ -91,7 +93,7 @@ public:
bool has_flat_cli_name() const noexcept;
private:
string_view buf_slice(size_t from, size_t to) const noexcept;
std::string_view buf_slice(size_t from, size_t to) const noexcept;
std::unique_ptr<char[]> buf_;
uint16_t category_separator_;
......@@ -104,15 +106,16 @@ private:
/// Finds `config_option` string with a matching long name in (`first`, `last`],
/// where each entry is a pointer to a string. Returns a `ForwardIterator` to
/// the match and a `caf::string_view` of the option value if the entry is found
/// and a `ForwardIterator` to `last` with an empty `string_view` otherwise.
/// the match and a `string_view` of the option value if the entry is
/// found and a `ForwardIterator` to `last` with an empty `string_view`
/// otherwise.
template <class ForwardIterator, class Sentinel>
std::pair<ForwardIterator, string_view>
std::pair<ForwardIterator, std::string_view>
find_by_long_name(const config_option& x, ForwardIterator first,
Sentinel last) {
auto long_name = x.long_name();
for (; first != last; ++first) {
string_view str{*first};
std::string_view str{*first};
// Make sure this is a long option starting with "--".
if (!starts_with(str, "--"))
continue;
......@@ -131,7 +134,7 @@ find_by_long_name(const config_option& x, ForwardIterator first,
str.remove_prefix(1);
return {first, str};
}
return {first, string_view{}};
return {first, std::string_view{}};
}
} // namespace caf
......@@ -17,26 +17,28 @@ class CAF_CORE_EXPORT config_option_adder {
public:
// -- constructors, destructors, and assignment operators --------------------
config_option_adder(config_option_set& target, string_view category);
config_option_adder(config_option_set& target, std::string_view category);
// -- properties -------------------------------------------------------------
/// Adds a config option to the category that synchronizes with `ref`.
template <class T>
config_option_adder& add(T& ref, string_view name, string_view description) {
config_option_adder&
add(T& ref, std::string_view name, std::string_view description) {
return add_impl(make_config_option(ref, category_, name, description));
}
/// Adds a config option to the category.
template <class T>
config_option_adder& add(string_view name, string_view description) {
config_option_adder&
add(std::string_view name, std::string_view description) {
return add_impl(make_config_option<T>(category_, name, description));
}
/// For backward compatibility only. Do not use for new code!
/// @private
config_option_adder&
add_neg(bool& ref, string_view name, string_view description);
config_option_adder& add_neg(bool& ref, std::string_view name,
std::string_view description);
private:
// -- properties -------------------------------------------------------------
......@@ -49,7 +51,7 @@ private:
config_option_set& xs_;
/// Category for all options generated by this adder.
string_view category_;
std::string_view category_;
};
} // namespace caf
......@@ -7,6 +7,7 @@
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
......@@ -15,7 +16,6 @@
#include "caf/fwd.hpp"
#include "caf/make_config_option.hpp"
#include "caf/pec.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -50,21 +50,21 @@ public:
/// `<prefix>#<category>.<long-name>`. Users can omit `<prefix>`
/// for options that have an empty prefix and `<category>`
/// if the category is "global".
option_pointer cli_long_name_lookup(string_view name) const;
option_pointer cli_long_name_lookup(std::string_view name) const;
/// Returns the first `config_option` that matches the CLI short option name.
option_pointer cli_short_name_lookup(char short_name) const;
/// Returns the first `config_option` that matches category and long name.
option_pointer
qualified_name_lookup(string_view category, string_view long_name) const;
option_pointer qualified_name_lookup(std::string_view category,
std::string_view long_name) const;
/// Returns the first `config_option` that matches the qualified name.
/// @param name Config option name formatted as `<category>.<long-name>`.
option_pointer qualified_name_lookup(string_view name) const;
option_pointer qualified_name_lookup(std::string_view name) const;
/// Returns whether a @ref config_option for the given category exists.
bool has_category(string_view category) const noexcept;
bool has_category(std::string_view category) const noexcept;
/// Returns the number of stored config options.
size_t size() const noexcept {
......@@ -98,54 +98,59 @@ public:
/// Adds a config option to the set.
template <class T>
config_option_set&
add(string_view category, string_view name, string_view description) & {
config_option_set& add(std::string_view category, std::string_view name,
std::string_view description) & {
return add(make_config_option<T>(category, name, description));
}
/// Adds a config option to the set.
template <class T>
config_option_set& add(string_view name, string_view description) & {
config_option_set&
add(std::string_view name, std::string_view description) & {
return add(make_config_option<T>("global", name, description));
}
/// Adds a config option to the set.
template <class T>
config_option_set&&
add(string_view category, string_view name, string_view description) && {
config_option_set&& add(std::string_view category, std::string_view name,
std::string_view description) && {
return std::move(add<T>(category, name, description));
}
/// Adds a config option to the set.
template <class T>
config_option_set&& add(string_view name, string_view description) && {
config_option_set&&
add(std::string_view name, std::string_view description) && {
return std::move(add<T>("global", name, description));
}
/// Adds a config option to the set that synchronizes its value with `ref`.
template <class T>
config_option_set& add(T& ref, string_view category, string_view name,
string_view description) & {
config_option_set& add(T& ref, std::string_view category,
std::string_view name,
std::string_view description) & {
return add(make_config_option<T>(ref, category, name, description));
}
/// Adds a config option to the set that synchronizes its value with `ref`.
template <class T>
config_option_set& add(T& ref, string_view name, string_view description) & {
config_option_set&
add(T& ref, std::string_view name, std::string_view description) & {
return add(ref, "global", name, description);
}
/// Adds a config option to the set that synchronizes its value with `ref`.
template <class T>
config_option_set&& add(T& ref, string_view category, string_view name,
string_view description) && {
config_option_set&& add(T& ref, std::string_view category,
std::string_view name,
std::string_view description) && {
return std::move(add(ref, category, name, description));
}
/// Adds a config option to the set that synchronizes its value with `ref`.
template <class T>
config_option_set&&
add(T& ref, string_view name, string_view description) && {
add(T& ref, std::string_view name, std::string_view description) && {
return std::move(add(ref, "global", name, description));
}
......@@ -163,12 +168,12 @@ public:
// -- parsing ----------------------------------------------------------------
/// Parses a given range as CLI arguments into `config`.
parse_result
parse(settings& config, argument_iterator begin, argument_iterator end) const;
parse_result parse(settings& config, argument_iterator begin,
argument_iterator end) const;
/// Parses a given range as CLI arguments into `config`.
parse_result
parse(settings& config, const std::vector<std::string>& args) const;
parse_result parse(settings& config,
const std::vector<std::string>& args) const;
private:
// -- member variables -------------------------------------------------------
......
......@@ -11,7 +11,9 @@
#include <iosfwd>
#include <iterator>
#include <map>
#include <optional>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <vector>
......@@ -28,10 +30,8 @@
#include "caf/fwd.hpp"
#include "caf/inspector_access.hpp"
#include "caf/inspector_access_type.hpp"
#include "caf/optional.hpp"
#include "caf/raise_error.hpp"
#include "caf/string_algorithms.hpp"
#include "caf/string_view.hpp"
#include "caf/sum_type.hpp"
#include "caf/sum_type_access.hpp"
#include "caf/sum_type_token.hpp"
......@@ -122,16 +122,16 @@ public:
// -- parsing ----------------------------------------------------------------
/// Tries to parse a value from given characters.
static expected<config_value> parse(string_view::iterator first,
string_view::iterator last);
static expected<config_value> parse(std::string_view::iterator first,
std::string_view::iterator last);
/// Tries to parse a value from `str`.
static expected<config_value> parse(string_view str);
static expected<config_value> parse(std::string_view str);
/// Tries to parse a config value (list) from `str` and to convert it to an
/// allowed input message type for `Handle`.
template <class Handle>
static optional<message> parse_msg(string_view str, const Handle&) {
static std::optional<message> parse_msg(std::string_view str, const Handle&) {
auto allowed = Handle::allowed_inputs();
return parse_msg_impl(str, allowed);
}
......@@ -249,7 +249,7 @@ public:
}
template <class T>
static constexpr string_view mapped_type_name() {
static constexpr std::string_view mapped_type_name() {
if constexpr (detail::is_complete<caf::type_name<T>>) {
return caf::type_name<T>::value;
} else if constexpr (detail::is_list_like_v<T>) {
......@@ -264,8 +264,8 @@ private:
static const char* type_name_at_index(size_t index) noexcept;
static optional<message>
parse_msg_impl(string_view str, span<const type_id_list> allowed_types);
static std::optional<message>
parse_msg_impl(std::string_view str, span<const type_id_list> allowed_types);
// -- auto conversion of related types ---------------------------------------
......@@ -309,7 +309,7 @@ private:
data_ = std::string{x};
}
void set(string_view x) {
void set(std::string_view x) {
data_ = std::string{x.begin(), x.end()};
}
......@@ -500,8 +500,9 @@ expected<T> get_as(const config_value& value) {
/// Customization point for configuring automatic mappings from default value
/// types to deduced types. For example, `get_or(value, "foo"sv)` must return a
/// `string` rather than a `string_view`. However, user-defined overloads *must
/// not* specialize this class for any type from the namespaces `std` or `caf`.
/// `string` rather than a `string_view`. However, user-defined overloads
/// *must not* specialize this class for any type from the namespaces `std` or
/// `caf`.
template <class T>
struct get_or_deduction_guide {
using value_type = T;
......@@ -512,9 +513,9 @@ struct get_or_deduction_guide {
};
template <>
struct get_or_deduction_guide<string_view> {
struct get_or_deduction_guide<std::string_view> {
using value_type = std::string;
static value_type convert(string_view str) {
static value_type convert(std::string_view str) {
return {str.begin(), str.end()};
}
};
......
......@@ -90,18 +90,18 @@ public:
bool fetch_next_object_type(type_id_t& type) override;
bool begin_object(type_id_t type, string_view name) override;
bool begin_object(type_id_t type, std::string_view name) override;
bool end_object() override;
bool begin_field(string_view) override;
bool begin_field(std::string_view) override;
bool begin_field(string_view name, bool& is_present) override;
bool begin_field(std::string_view name, bool& is_present) override;
bool begin_field(string_view name, span<const type_id_t> types,
bool begin_field(std::string_view name, span<const type_id_t> types,
size_t& index) override;
bool begin_field(string_view name, bool& is_present,
bool begin_field(std::string_view name, bool& is_present,
span<const type_id_t> types, size_t& index) override;
bool end_field() override;
......@@ -122,7 +122,7 @@ public:
bool end_associative_array() override;
bool value(byte& x) override;
bool value(std::byte& x) override;
bool value(bool& x) override;
......@@ -154,7 +154,7 @@ public:
bool value(std::u32string& x) override;
bool value(span<byte> x) override;
bool value(span<std::byte> x) override;
private:
// Sets `type` according to the `@type` field in `obj` or to the type ID of
......
......@@ -22,8 +22,8 @@ public:
struct present_field {
settings* parent;
string_view name;
string_view type;
std::string_view name;
std::string_view type;
};
struct absent_field {};
......@@ -54,18 +54,18 @@ public:
// -- interface functions ----------------------------------------------------
bool begin_object(type_id_t type, string_view name) override;
bool begin_object(type_id_t type, std::string_view name) override;
bool end_object() override;
bool begin_field(string_view) override;
bool begin_field(std::string_view) override;
bool begin_field(string_view name, bool is_present) override;
bool begin_field(std::string_view name, bool is_present) override;
bool begin_field(string_view name, span<const type_id_t> types,
bool begin_field(std::string_view name, span<const type_id_t> types,
size_t index) override;
bool begin_field(string_view name, bool is_present,
bool begin_field(std::string_view name, bool is_present,
span<const type_id_t> types, size_t index) override;
bool end_field() override;
......@@ -86,7 +86,7 @@ public:
bool end_associative_array() override;
bool value(byte x) override;
bool value(std::byte x) override;
bool value(bool x) override;
......@@ -112,13 +112,13 @@ public:
bool value(long double x) override;
bool value(string_view x) override;
bool value(std::string_view x) override;
bool value(const std::u16string& x) override;
bool value(const std::u32string& x) override;
bool value(span<const byte> x) override;
bool value(span<const std::byte> x) override;
private:
bool push(config_value&& x);
......
......@@ -4,6 +4,7 @@
#pragma once
#include <optional>
#include <utility>
#include "caf/detail/message_data.hpp"
......@@ -27,8 +28,8 @@ public:
const_typed_message_view(const const_typed_message_view&) noexcept = default;
const_typed_message_view& operator=(const const_typed_message_view&) noexcept
= default;
const_typed_message_view&
operator=(const const_typed_message_view&) noexcept = default;
const detail::message_data* operator->() const noexcept {
return ptr_;
......@@ -67,10 +68,10 @@ auto make_const_typed_message_view(const message& msg) {
}
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))
return to_tuple(view);
return none;
return std::nullopt;
}
} // namespace caf
......@@ -130,12 +130,13 @@ struct inspector_access<cow_tuple<Ts...>> {
}
template <class Inspector>
static bool save_field(Inspector& f, string_view field_name, value_type& x) {
static bool
save_field(Inspector& f, std::string_view field_name, value_type& x) {
return detail::save_field(f, field_name, detail::as_mutable_ref(x.data()));
}
template <class Inspector, class IsPresent, class Get>
static bool save_field(Inspector& f, string_view field_name,
static bool save_field(Inspector& f, std::string_view field_name,
IsPresent& is_present, Get& get) {
if constexpr (std::is_lvalue_reference<decltype(get())>::value) {
auto get_data = [&get]() -> decltype(auto) {
......@@ -152,16 +153,17 @@ struct inspector_access<cow_tuple<Ts...>> {
}
template <class Inspector, class IsValid, class SyncValue>
static bool load_field(Inspector& f, string_view field_name, value_type& x,
IsValid& is_valid, SyncValue& sync_value) {
static bool load_field(Inspector& f, std::string_view field_name,
value_type& x, IsValid& is_valid,
SyncValue& sync_value) {
return detail::load_field(f, field_name, x.unshared(), is_valid,
sync_value);
}
template <class Inspector, class IsValid, class SyncValue, class SetFallback>
static bool load_field(Inspector& f, string_view field_name, value_type& x,
IsValid& is_valid, SyncValue& sync_value,
SetFallback& set_fallback) {
static bool load_field(Inspector& f, std::string_view field_name,
value_type& x, IsValid& is_valid,
SyncValue& sync_value, SetFallback& set_fallback) {
return detail::load_field(f, field_name, x.unshared(), is_valid, sync_value,
set_fallback);
}
......
......@@ -9,7 +9,6 @@
#include "caf/detail/implicit_conversions.hpp"
#include "caf/expected.hpp"
#include "caf/fwd.hpp"
#include "caf/optional.hpp"
#include "caf/replies_to.hpp"
namespace caf::detail {
......
......@@ -5,10 +5,9 @@
#pragma once
#include <string>
#include <string_view>
#include <type_traits>
#include "caf/string_view.hpp"
namespace caf {
/// Convenience function for providing a default inspection scaffold for custom
......@@ -28,7 +27,7 @@ bool default_enum_inspect(Inspector& f, Enumeration& x) {
using integer_type = std::underlying_type_t<Enumeration>;
if (f.has_human_readable_format()) {
auto get = [&x] { return to_string(x); };
auto set = [&x](string_view str) { return from_string(str, x); };
auto set = [&x](std::string_view str) { return from_string(str, x); };
return f.apply(get, set);
} else {
auto get = [&x] { return static_cast<integer_type>(x); };
......
......@@ -8,11 +8,11 @@
#include <cstddef>
#include <limits>
#include <string>
#include <string_view>
#include <vector>
#include "caf/detail/build_config.hpp"
#include "caf/detail/log_level.hpp"
#include "caf/string_view.hpp"
#include "caf/timestamp.hpp"
// -- hard-coded default values for various CAF options ------------------------
......@@ -29,7 +29,7 @@ constexpr auto max_batch_delay = timespan{1'000'000};
/// The `token-based` controller associates each stream element with one token.
/// Input buffer and batch sizes are then statically defined in terms of tokens.
/// This strategy makes no dynamic adjustment or sampling.
constexpr auto credit_policy = string_view{"size-based"};
constexpr auto credit_policy = std::string_view{"size-based"};
} // namespace caf::defaults::stream
......@@ -71,8 +71,8 @@ constexpr auto buffer_size = int32_t{4096}; // // 32 KB for elements of size 8.
namespace caf::defaults::scheduler {
constexpr auto policy = string_view{"stealing"};
constexpr auto profiling_output_file = string_view{""};
constexpr auto policy = std::string_view{"stealing"};
constexpr auto profiling_output_file = std::string_view{""};
constexpr auto max_throughput = std::numeric_limits<size_t>::max();
constexpr auto profiling_resolution = timespan(100'000'000);
......@@ -92,22 +92,23 @@ constexpr auto relaxed_sleep_duration = timespan{10'000'000};
namespace caf::defaults::logger::file {
constexpr auto format = string_view{"%r %c %p %a %t %C %M %F:%L %m%n"};
constexpr auto path = string_view{"actor_log_[PID]_[TIMESTAMP]_[NODE].log"};
constexpr auto format = std::string_view{"%r %c %p %a %t %C %M %F:%L %m%n"};
constexpr auto path
= std::string_view{"actor_log_[PID]_[TIMESTAMP]_[NODE].log"};
} // namespace caf::defaults::logger::file
namespace caf::defaults::logger::console {
constexpr auto colored = true;
constexpr auto format = string_view{"[%c:%p] %d %m"};
constexpr auto format = std::string_view{"[%c:%p] %d %m"};
} // namespace caf::defaults::logger::console
namespace caf::defaults::middleman {
constexpr auto app_identifier = string_view{"generic-caf-app"};
constexpr auto network_backend = string_view{"default"};
constexpr auto app_identifier = std::string_view{"generic-caf-app"};
constexpr auto network_backend = std::string_view{"default"};
constexpr auto max_consecutive_reads = size_t{50};
constexpr auto heartbeat_interval = timespan{10'000'000'000};
constexpr auto connection_timeout = timespan{30'000'000'000};
......
......@@ -10,7 +10,6 @@
#include <type_traits>
#include <utility>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
......@@ -61,35 +60,36 @@ public:
/// that becomes invalid as soon as calling *any* other member
/// function on the deserializer. Convert the `type_name` to a string
/// before storing it.
virtual bool fetch_next_object_name(string_view& type_name);
virtual bool fetch_next_object_name(std::string_view& type_name);
/// Convenience function for querying `fetch_next_object_name` comparing the
/// result to `type_name` in one shot.
bool next_object_name_matches(string_view type_name);
bool next_object_name_matches(std::string_view type_name);
/// Like `next_object_name_matches`, but sets an error on the deserializer
/// on a mismatch.
bool assert_next_object_name(string_view type_name);
bool assert_next_object_name(std::string_view type_name);
/// Begins processing of an object, may perform a type check depending on the
/// data format.
/// @param type 16-bit ID for known types, @ref invalid_type_id otherwise.
/// @param pretty_class_name Either the output of @ref type_name_or_anonymous
/// or the optionally defined pretty name.
virtual bool begin_object(type_id_t type, string_view pretty_class_name) = 0;
virtual bool begin_object(type_id_t type, std::string_view pretty_class_name)
= 0;
/// Ends processing of an object.
virtual bool end_object() = 0;
virtual bool begin_field(string_view name) = 0;
virtual bool begin_field(std::string_view name) = 0;
virtual bool begin_field(string_view, bool& is_present) = 0;
virtual bool begin_field(std::string_view, bool& is_present) = 0;
virtual bool
begin_field(string_view name, span<const type_id_t> types, size_t& index)
begin_field(std::string_view name, span<const type_id_t> types, size_t& index)
= 0;
virtual bool begin_field(string_view name, bool& is_present,
virtual bool begin_field(std::string_view name, bool& is_present,
span<const type_id_t> types, size_t& index)
= 0;
......@@ -127,7 +127,7 @@ public:
/// Reads `x` from the input.
/// @param x A reference to a builtin type.
/// @returns `true` on success, `false` otherwise.
virtual bool value(byte& x) = 0;
virtual bool value(std::byte& x) = 0;
/// @copydoc value
virtual bool value(bool& x) = 0;
......@@ -188,13 +188,13 @@ public:
/// Reads a byte sequence from the input.
/// @param x The byte sequence.
/// @returns A non-zero error code on failure, `sec::success` otherwise.
virtual bool value(span<byte> x) = 0;
virtual bool value(span<std::byte> x) = 0;
using super::list;
/// Adds each boolean in `xs` to the output. Derived classes can override this
/// member function to pack the booleans, for example to avoid using one byte
/// for each value in a binary output format.
/// member function to pack the booleans, for example to avoid using one
/// byte for each value in a binary output format.
virtual bool list(std::vector<bool>& xs);
protected:
......
......@@ -4,10 +4,10 @@
#pragma once
#include <cstddef>
#include <string>
#include <type_traits>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/type_traits.hpp"
......
......@@ -7,25 +7,25 @@
#include "caf/byte_buffer.hpp"
#include "caf/byte_span.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/optional.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
#include <optional>
#include <string>
#include <string_view>
namespace caf::detail {
class CAF_CORE_EXPORT base64 {
public:
static void encode(string_view str, std::string& out);
static void encode(std::string_view str, std::string& out);
static void encode(string_view str, byte_buffer& out);
static void encode(std::string_view str, byte_buffer& out);
static void encode(const_byte_span bytes, std::string& out);
static void encode(const_byte_span bytes, byte_buffer& out);
static std::string encode(string_view str) {
static std::string encode(std::string_view str) {
std::string result;
encode(str, result);
return result;
......@@ -37,15 +37,15 @@ public:
return result;
}
static bool decode(string_view in, std::string& out);
static bool decode(std::string_view in, std::string& out);
static bool decode(string_view in, byte_buffer& out);
static bool decode(std::string_view in, byte_buffer& out);
static bool decode(const_byte_span bytes, std::string& 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(std::string_view in) {
std::string result;
if (decode(in, result))
return {std::move(result)};
......@@ -53,7 +53,7 @@ public:
return {};
}
static optional<std::string> decode(const_byte_span in) {
static std::optional<std::string> decode(const_byte_span in) {
std::string result;
if (decode(in, result))
return {std::move(result)};
......
......@@ -4,6 +4,7 @@
#pragma once
#include <optional>
#include <tuple>
#include <type_traits>
#include <utility>
......@@ -19,7 +20,6 @@
#include "caf/make_counted.hpp"
#include "caf/message.hpp"
#include "caf/none.hpp"
#include "caf/optional.hpp"
#include "caf/ref_counted.hpp"
#include "caf/response_promise.hpp"
#include "caf/skip.hpp"
......@@ -51,7 +51,7 @@ public:
virtual bool invoke(detail::invoke_result_visitor& f, message& xs) = 0;
optional<message> invoke(message&);
std::optional<message> invoke(message&);
virtual void handle_timeout();
......
......@@ -14,7 +14,6 @@
#include "caf/detail/core_export.hpp"
#include "caf/mailbox_element.hpp"
#include "caf/message_id.hpp"
#include "caf/optional.hpp"
namespace caf::detail {
......
......@@ -13,8 +13,6 @@
#include "caf/detail/type_traits.hpp"
#include "caf/fwd.hpp"
#include "caf/message.hpp"
#include "caf/none.hpp"
#include "caf/optional.hpp"
#include "caf/result.hpp"
#include "caf/skip.hpp"
#include "caf/unit.hpp"
......
......@@ -5,12 +5,12 @@
#pragma once
#include <cstdint>
#include <string_view>
#include <variant>
#include <vector>
#include "caf/detail/monotonic_buffer_resource.hpp"
#include "caf/parser_state.hpp"
#include "caf/string_view.hpp"
// This JSON abstraction is designed to allocate its entire state in a monotonic
// buffer resource. This minimizes memory allocations and also enables us to
......@@ -29,7 +29,7 @@ public:
using array = std::vector<value, array_allocator>;
struct member {
string_view key;
std::string_view key;
value* val = nullptr;
};
......@@ -37,8 +37,8 @@ public:
using object = std::vector<member, member_allocator>;
using data_type
= std::variant<null_t, int64_t, double, bool, string_view, array, object>;
using data_type = std::variant<null_t, int64_t, double, bool,
std::string_view, array, object>;
static constexpr size_t null_index = 0;
......
......@@ -10,7 +10,6 @@
#include "caf/allowed_unsafe_message_type.hpp"
#include "caf/binary_deserializer.hpp"
#include "caf/binary_serializer.hpp"
#include "caf/byte.hpp"
#include "caf/deserializer.hpp"
#include "caf/detail/meta_object.hpp"
#include "caf/detail/padded_size.hpp"
......@@ -73,7 +72,7 @@ void stringify(std::string& buf, const void* ptr) {
namespace caf::detail {
template <class T>
meta_object make_meta_object(string_view type_name) {
meta_object make_meta_object(std::string_view type_name) {
return {
type_name,
padded_size_v<T>,
......
......@@ -4,10 +4,10 @@
#pragma once
#include <cstddef>
#include <memory>
#include <new>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/padded_size.hpp"
......@@ -25,14 +25,16 @@ public:
/// Uses placement new to create a copy of the wrapped value at given memory
/// region.
/// @returns the past-the-end pointer of the object, i.e., the first byte for
/// @returns the past-the-end pointer of the object, i.e., the first byte
/// for
/// the *next* object.
virtual byte* copy_init(byte* storage) const = 0;
virtual std::byte* copy_init(std::byte* storage) const = 0;
/// Uses placement new to move the wrapped value to given memory region.
/// @returns the past-the-end pointer of the object, i.e., the first byte for
/// @returns the past-the-end pointer of the object, i.e., the first byte
/// for
/// the *next* object.
virtual byte* move_init(byte* storage) = 0;
virtual std::byte* move_init(std::byte* storage) = 0;
};
template <class T>
......@@ -56,12 +58,12 @@ public:
message_builder_element_impl& operator=(const message_builder_element_impl&)
= delete;
byte* copy_init(byte* storage) const override {
std::byte* copy_init(std::byte* storage) const override {
new (storage) T(value_);
return storage + padded_size_v<T>;
}
byte* move_init(byte* storage) override {
std::byte* move_init(std::byte* storage) override {
new (storage) T(std::move(value_));
return storage + padded_size_v<T>;
}
......
......@@ -5,10 +5,10 @@
#pragma once
#include <atomic>
#include <cstddef>
#include <cstdlib>
#include <new>
#include "caf/byte.hpp"
#include "caf/config.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/implicit_conversions.hpp"
......@@ -78,12 +78,12 @@ public:
}
/// Returns the memory region for storing the message elements.
byte* storage() noexcept {
std::byte* storage() noexcept {
return storage_;
}
/// @copydoc storage
const byte* storage() const noexcept {
const std::byte* storage() const noexcept {
return storage_;
}
......@@ -99,10 +99,10 @@ public:
/// Returns the memory location for the object at given index.
/// @pre `index < size()`
byte* at(size_t index) noexcept;
std::byte* at(size_t index) noexcept;
/// @copydoc at
const byte* at(size_t index) const noexcept;
const std::byte* at(size_t index) const noexcept;
void inc_constructed_elements() {
++constructed_elements_;
......@@ -113,41 +113,42 @@ public:
init_impl(storage(), std::forward<Ts>(xs)...);
}
byte* stepwise_init(byte* pos) {
std::byte* stepwise_init(std::byte* pos) {
return pos;
}
template <class T, class... Ts>
byte* stepwise_init(byte* pos, T&& x, Ts&&... xs) {
std::byte* stepwise_init(std::byte* pos, T&& x, Ts&&... xs) {
using type = strip_and_convert_t<T>;
new (pos) type(std::forward<T>(x));
++constructed_elements_;
return stepwise_init(pos + padded_size_v<type>, std::forward<Ts>(xs)...);
}
byte* stepwise_init_from(byte* pos, const message& msg);
std::byte* stepwise_init_from(std::byte* pos, const message& msg);
byte* stepwise_init_from(byte* pos, const message_data* other);
std::byte* stepwise_init_from(std::byte* pos, const message_data* other);
template <class Tuple, size_t... Is>
byte* stepwise_init_from(byte* pos, Tuple&& tup, std::index_sequence<Is...>) {
std::byte*
stepwise_init_from(std::byte* pos, Tuple&& tup, std::index_sequence<Is...>) {
return stepwise_init(pos, std::get<Is>(std::forward<Tuple>(tup))...);
}
template <class... Ts>
byte* stepwise_init_from(byte* pos, std::tuple<Ts...>&& tup) {
std::byte* stepwise_init_from(std::byte* pos, std::tuple<Ts...>&& tup) {
return stepwise_init_from(pos, std::move(tup),
std::make_index_sequence<sizeof...(Ts)>{});
}
template <class... Ts>
byte* stepwise_init_from(byte* pos, std::tuple<Ts...>& tup) {
std::byte* stepwise_init_from(std::byte* pos, std::tuple<Ts...>& tup) {
return stepwise_init_from(pos, tup,
std::make_index_sequence<sizeof...(Ts)>{});
}
template <class... Ts>
byte* stepwise_init_from(byte* pos, const std::tuple<Ts...>& tup) {
std::byte* stepwise_init_from(std::byte* pos, const std::tuple<Ts...>& tup) {
return stepwise_init_from(pos, tup,
std::make_index_sequence<sizeof...(Ts)>{});
}
......@@ -158,24 +159,24 @@ public:
}
private:
void init_impl(byte*) {
void init_impl(std::byte*) {
// End of recursion.
}
template <class T, class... Ts>
void init_impl(byte* storage, T&& x, Ts&&... xs) {
void init_impl(std::byte* storage, T&& x, Ts&&... xs) {
using type = strip_and_convert_t<T>;
new (storage) type(std::forward<T>(x));
++constructed_elements_;
init_impl(storage + padded_size_v<type>, std::forward<Ts>(xs)...);
}
void init_from_impl(byte*) {
void init_from_impl(std::byte*) {
// End of recursion.
}
template <class T, class... Ts>
void init_from_impl(byte* pos, T&& x, Ts&&... xs) {
void init_from_impl(std::byte* pos, T&& x, Ts&&... xs) {
init_from_impl(stepwise_init_from(pos, std::forward<T>(x)),
std::forward<Ts>(xs)...);
}
......@@ -183,7 +184,7 @@ private:
mutable std::atomic<size_t> rc_;
type_id_list types_;
size_t constructed_elements_;
byte storage_[];
std::byte storage_[];
};
// -- related non-members ------------------------------------------------------
......
......@@ -6,11 +6,11 @@
#include <cstddef>
#include <cstdint>
#include <string_view>
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
namespace caf::detail {
......@@ -18,7 +18,7 @@ namespace caf::detail {
/// pointers.
struct meta_object {
/// Stores a human-readable representation of the type's name.
string_view type_name;
std::string_view type_name;
/// Stores how many Bytes objects of this type require, including padding for
/// aligning to `max_align_t`.
......
......@@ -8,7 +8,6 @@
#include "caf/detail/core_export.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/none.hpp"
#include "caf/optional.hpp"
#include "caf/response_promise.hpp"
#include "caf/skip.hpp"
#include "caf/static_visitor.hpp"
......@@ -42,16 +41,16 @@ template <class T>
struct optional_message_visitor_enable_tpl {
static constexpr bool value
= !is_one_of<typename std::remove_const<T>::type, none_t, unit_t, skip_t,
optional<skip_t>>::value
std::optional<skip_t>>::value
&& !is_message_id_wrapper<T>::value && !is_response_promise<T>::value;
};
class CAF_CORE_EXPORT optional_message_visitor
: public static_visitor<optional<message>> {
: public static_visitor<std::optional<message>> {
public:
optional_message_visitor() = default;
using opt_msg = optional<message>;
using opt_msg = std::optional<message>;
opt_msg operator()(const none_t&) const {
return none;
......@@ -65,7 +64,7 @@ public:
return message{};
}
opt_msg operator()(optional<skip_t>& val) const {
opt_msg operator()(std::optional<skip_t>& val) const {
if (val)
return none;
return message{};
......@@ -101,7 +100,7 @@ public:
}
template <class T>
opt_msg operator()(optional<T>& value) const {
opt_msg operator()(std::optional<T>& value) const {
if (value)
return (*this)(*value);
if (value.empty())
......
......@@ -7,6 +7,7 @@
#include <cstdint>
#include <cstring>
#include <iterator>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
......@@ -19,7 +20,6 @@
#include "caf/message.hpp"
#include "caf/none.hpp"
#include "caf/parser_state.hpp"
#include "caf/string_view.hpp"
#include "caf/unit.hpp"
namespace caf::detail {
......@@ -39,7 +39,7 @@ enum class time_unit {
CAF_CORE_EXPORT void parse(string_parser_state& ps, time_unit& x);
struct literal {
string_view str;
std::string_view str;
};
CAF_CORE_EXPORT void parse(string_parser_state& ps, literal x);
......@@ -230,17 +230,17 @@ void parse(string_parser_state& ps,
// -- convenience functions ----------------------------------------------------
CAF_CORE_EXPORT
error parse_result(const string_parser_state& ps, string_view input);
error parse_result(const string_parser_state& ps, std::string_view input);
template <class T>
auto parse(string_view str, T& x) {
auto parse(std::string_view str, T& x) {
string_parser_state ps{str.begin(), str.end()};
parse(ps, x);
return parse_result(ps, str);
}
template <class T, class Policy>
auto parse(string_view str, T& x, Policy policy) {
auto parse(std::string_view str, T& x, Policy policy) {
string_parser_state ps{str.begin(), str.end()};
parse(ps, x, policy);
return parse_result(ps, str);
......
......@@ -5,6 +5,7 @@
#pragma once
#include <cstdint>
#include <optional>
#include <type_traits>
#include "caf/config.hpp"
......@@ -14,7 +15,6 @@
#include "caf/detail/parser/is_digit.hpp"
#include "caf/detail/parser/sub_ascii.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/optional.hpp"
#include "caf/pec.hpp"
CAF_PUSH_UNUSED_LABEL_WARNING
......@@ -30,7 +30,7 @@ namespace caf::detail::parser {
/// the pre-decimal value.
template <class State, class Consumer, class ValueType>
void read_floating_point(State& ps, Consumer&& consumer,
optional<ValueType> start_value,
std::optional<ValueType> start_value,
bool negative = false) {
// Any exponent larger than 511 always overflows.
static constexpr int max_double_exponent = 511;
......@@ -38,7 +38,7 @@ void read_floating_point(State& ps, Consumer&& consumer,
enum sign_t { plus, minus };
sign_t sign;
ValueType result;
if (start_value == none) {
if (!start_value) {
sign = plus;
result = 0;
} else if (*start_value < 0) {
......@@ -72,8 +72,8 @@ void read_floating_point(State& ps, Consumer&& consumer,
}
// 3) Scale result.
// Pre-computed powers of 10 for the scaling loop.
static double powerTable[]
= {1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 1e64, 1e128, 1e256};
static double powerTable[] = {1e1, 1e2, 1e4, 1e8, 1e16,
1e32, 1e64, 1e128, 1e256};
auto i = 0;
if (exp < 0) {
for (auto n = -exp; n != 0; n >>= 1, ++i)
......@@ -97,7 +97,7 @@ void read_floating_point(State& ps, Consumer&& consumer,
// Definition of our parser FSM.
start();
unstable_state(init) {
epsilon_if(start_value == none, regular_init)
epsilon_if(!start_value, regular_init)
epsilon(after_dec, "eE.")
epsilon(after_dot, any_char)
}
......@@ -173,7 +173,7 @@ template <class State, class Consumer>
void read_floating_point(State& ps, Consumer&& consumer) {
using consumer_type = typename std::decay<Consumer>::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
......
......@@ -50,7 +50,7 @@ void read_number(State& ps, Consumer& consumer, EnableFloat = {},
if (ps.code <= pec::trailing_character)
consumer.value(result);
});
using odbl = optional<double>;
using odbl = std::optional<double>;
// clang-format off
// Definition of our parser FSM.
start();
......@@ -179,8 +179,8 @@ void read_number(State& ps, Consumer& consumer, EnableFloat = {},
template <class State, class Consumer>
void read_number_range(State& ps, Consumer& consumer, int64_t begin) {
optional<int64_t> end;
optional<int64_t> step;
std::optional<int64_t> end;
std::optional<int64_t> step;
auto end_consumer = make_consumer(end);
auto step_consumer = make_consumer(step);
auto generate_2 = [&](int64_t n, int64_t m) {
......
......@@ -15,7 +15,6 @@
#include "caf/detail/parser/read_timespan.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/none.hpp"
#include "caf/optional.hpp"
#include "caf/pec.hpp"
#include "caf/timestamp.hpp"
#include "caf/variant.hpp"
......
......@@ -6,12 +6,12 @@
#include <chrono>
#include <cstdint>
#include <optional>
#include <string>
#include "caf/config.hpp"
#include "caf/detail/parser/read_signed_integer.hpp"
#include "caf/detail/scope_guard.hpp"
#include "caf/optional.hpp"
#include "caf/pec.hpp"
#include "caf/timestamp.hpp"
......@@ -24,7 +24,7 @@ namespace caf::detail::parser {
/// Reads a timespan.
template <class State, class Consumer>
void read_timespan(State& ps, Consumer&& consumer,
optional<int64_t> num = none) {
std::optional<int64_t> num = std::nullopt) {
using namespace std::chrono;
struct interim_consumer {
using value_type = int64_t;
......
......@@ -4,13 +4,14 @@
#pragma once
#include "caf/detail/core_export.hpp"
#include "caf/none.hpp"
#include "caf/string_view.hpp"
#include <chrono>
#include <cstdint>
#include <ctime>
#include <limits>
#include <string_view>
#include <type_traits>
namespace caf::detail {
......@@ -19,7 +20,7 @@ CAF_CORE_EXPORT
size_t print_timestamp(char* buf, size_t buf_size, time_t ts, size_t ms);
template <class Buffer>
void print_escaped(Buffer& buf, string_view str) {
void print_escaped(Buffer& buf, std::string_view str) {
buf.push_back('"');
for (auto c : str) {
switch (c) {
......@@ -64,7 +65,7 @@ void print_escaped(Buffer& buf, string_view str) {
}
template <class Buffer>
void print_unescaped(Buffer& buf, string_view str) {
void print_unescaped(Buffer& buf, std::string_view str) {
buf.reserve(buf.size() + str.size());
auto i = str.begin();
auto e = str.end();
......@@ -112,15 +113,15 @@ void print_unescaped(Buffer& buf, string_view str) {
template <class Buffer>
void print(Buffer& buf, none_t) {
using namespace caf::literals;
auto str = "null"_sv;
using namespace std::literals;
auto str = "null"sv;
buf.insert(buf.end(), str.begin(), str.end());
}
template <class Buffer>
void print(Buffer& buf, bool x) {
using namespace caf::literals;
auto str = x ? "true"_sv : "false"_sv;
using namespace std::literals;
auto str = x ? "true"sv : "false"sv;
buf.insert(buf.end(), str.begin(), str.end());
}
......@@ -132,20 +133,20 @@ std::enable_if_t<std::is_integral<T>::value> print(Buffer& buf, T x) {
// Convert negative values into positives as necessary.
if constexpr (std::is_signed<T>::value) {
if (x == std::numeric_limits<T>::min()) {
using namespace caf::literals;
using namespace std::literals;
// The code below would fail for the smallest value, because this value
// has no positive counterpart. For example, an int8_t ranges from -128 to
// 127. Hence, an int8_t cannot represent `abs(-128)`.
string_view result;
std::string_view result;
if constexpr (sizeof(T) == 1) {
result = "-128"_sv;
result = "-128"sv;
} else if constexpr (sizeof(T) == 2) {
result = "-32768"_sv;
result = "-32768"sv;
} else if constexpr (sizeof(T) == 4) {
result = "-2147483648"_sv;
result = "-2147483648"sv;
} else {
static_assert(sizeof(T) == 8);
result = "-9223372036854775808"_sv;
result = "-9223372036854775808"sv;
}
buf.insert(buf.end(), result.begin(), result.end());
return;
......@@ -186,13 +187,13 @@ std::enable_if_t<std::is_floating_point<T>::value> print(Buffer& buf, T x) {
template <class Buffer, class Rep, class Period>
void print(Buffer& buf, std::chrono::duration<Rep, Period> x) {
using namespace caf::literals;
using namespace std::literals;
if (x.count() == 0) {
auto str = "0s"_sv;
auto str = "0s"sv;
buf.insert(buf.end(), str.begin(), str.end());
return;
}
auto try_print = [&buf](auto converted, string_view suffix) {
auto try_print = [&buf](auto converted, std::string_view suffix) {
if (converted.count() < 1)
return false;
print(buf, converted.count());
......@@ -213,7 +214,7 @@ void print(Buffer& buf, std::chrono::duration<Rep, Period> x) {
return;
auto converted = sc::duration_cast<sc::nanoseconds>(x);
print(buf, converted.count());
auto suffix = "ns"_sv;
auto suffix = "ns"sv;
buf.insert(buf.end(), suffix.begin(), suffix.end());
}
......
......@@ -18,19 +18,19 @@ public:
size_t result = 0;
bool begin_object(type_id_t, string_view) override;
bool begin_object(type_id_t, std::string_view) override;
bool end_object() override;
bool begin_field(string_view) override;
bool begin_field(std::string_view) override;
bool begin_field(string_view, bool is_present) override;
bool begin_field(std::string_view, bool is_present) override;
bool begin_field(string_view, span<const type_id_t> types,
bool begin_field(std::string_view, span<const type_id_t> types,
size_t index) override;
bool begin_field(string_view, bool is_present, span<const type_id_t> types,
size_t index) override;
bool begin_field(std::string_view, bool is_present,
span<const type_id_t> types, size_t index) override;
bool end_field() override;
......@@ -42,7 +42,7 @@ public:
bool end_sequence() override;
bool value(byte x) override;
bool value(std::byte x) override;
bool value(bool x) override;
......@@ -68,13 +68,13 @@ public:
bool value(long double x) override;
bool value(string_view x) override;
bool value(std::string_view x) override;
bool value(const std::u16string& x) override;
bool value(const std::u32string& x) override;
bool value(span<const byte> x) override;
bool value(span<const std::byte> x) override;
using super::list;
......
......@@ -7,6 +7,7 @@
#include <chrono>
#include <cstring>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
......@@ -14,7 +15,6 @@
#include "caf/fwd.hpp"
#include "caf/inspector_access.hpp"
#include "caf/save_inspector_base.hpp"
#include "caf/string_view.hpp"
#include "caf/timespan.hpp"
#include "caf/timestamp.hpp"
#include "caf/variant.hpp"
......@@ -44,17 +44,17 @@ public:
// -- serializer interface ---------------------------------------------------
bool begin_object(type_id_t, string_view name);
bool begin_object(type_id_t, std::string_view name);
bool end_object();
bool begin_field(string_view);
bool begin_field(std::string_view);
bool begin_field(string_view name, bool is_present);
bool begin_field(std::string_view name, bool is_present);
bool begin_field(string_view name, span<const type_id_t>, size_t);
bool begin_field(std::string_view name, span<const type_id_t>, size_t);
bool begin_field(string_view name, bool, span<const type_id_t>, size_t);
bool begin_field(std::string_view name, bool, span<const type_id_t>, size_t);
bool end_field();
......@@ -86,7 +86,7 @@ public:
return end_sequence();
}
bool value(byte x);
bool value(std::byte x);
bool value(bool x);
......@@ -108,13 +108,13 @@ public:
bool value(timestamp x);
bool value(string_view x);
bool value(std::string_view x);
bool value(const std::u16string& x);
bool value(const std::u32string& x);
bool value(span<const byte> x);
bool value(span<const std::byte> x);
using super::list;
......@@ -153,7 +153,7 @@ public:
template <class T>
std::enable_if_t<has_to_string<T>::value
&& !std::is_convertible<T, string_view>::value,
&& !std::is_convertible<T, std::string_view>::value,
bool>
builtin_inspect(const T& x) {
auto str = to_string(x);
......@@ -174,7 +174,7 @@ public:
result_ += "null";
return true;
} else if constexpr (std::is_same<T, char>::value) {
return value(string_view{x, strlen(x)});
return value(std::string_view{x, strlen(x)});
} else if constexpr (std::is_same<T, void>::value) {
sep();
result_ += "*<";
......@@ -191,7 +191,7 @@ public:
}
template <class T>
bool builtin_inspect(const optional<T>& x) {
bool builtin_inspect(const std::optional<T>& x) {
sep();
if (!x) {
result_ += "null";
......@@ -221,12 +221,12 @@ public:
static std::string render(const T& x) {
if constexpr (std::is_same<std::nullptr_t, T>::value) {
return "null";
} else if constexpr (std::is_constructible<string_view, T>::value) {
} else if constexpr (std::is_constructible<std::string_view, T>::value) {
if constexpr (std::is_pointer<T>::value) {
if (x == nullptr)
return "null";
}
auto str = string_view{x};
auto str = std::string_view{x};
return std::string{str.begin(), str.end()};
} else {
std::string result;
......
......@@ -925,7 +925,7 @@ struct is_trivial_inspector_value<true, T> {
template <class T>
struct is_trivial_inspector_value<false, T> {
static constexpr bool value = std::is_convertible<T, string_view>::value;
static constexpr bool value = std::is_convertible<T, std::string_view>::value;
};
#define CAF_ADD_TRIVIAL_LOAD_INSPECTOR_VALUE(type) \
......@@ -951,9 +951,9 @@ CAF_ADD_TRIVIAL_INSPECTOR_VALUE(long double)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(std::u16string)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(std::u32string)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(std::vector<bool>)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(span<byte>)
CAF_ADD_TRIVIAL_INSPECTOR_VALUE(span<std::byte>)
CAF_ADD_TRIVIAL_SAVE_INSPECTOR_VALUE(span<const byte>)
CAF_ADD_TRIVIAL_SAVE_INSPECTOR_VALUE(span<const std::byte>)
CAF_ADD_TRIVIAL_LOAD_INSPECTOR_VALUE(std::string)
......@@ -989,12 +989,12 @@ struct is_builtin_inspector_type {
};
template <bool IsLoading>
struct is_builtin_inspector_type<byte, IsLoading> {
struct is_builtin_inspector_type<std::byte, IsLoading> {
static constexpr bool value = true;
};
template <bool IsLoading>
struct is_builtin_inspector_type<span<byte>, IsLoading> {
struct is_builtin_inspector_type<span<std::byte>, IsLoading> {
static constexpr bool value = true;
};
......@@ -1014,12 +1014,12 @@ struct is_builtin_inspector_type<std::u32string, IsLoading> {
};
template <>
struct is_builtin_inspector_type<string_view, false> {
struct is_builtin_inspector_type<std::string_view, false> {
static constexpr bool value = true;
};
template <>
struct is_builtin_inspector_type<span<const byte>, false> {
struct is_builtin_inspector_type<span<const std::byte>, false> {
static constexpr bool value = true;
};
......
......@@ -9,14 +9,14 @@
#include <map>
#include <ostream>
#include <string>
#include <string_view>
#include "caf/deep_to_string.hpp"
#include "caf/string_view.hpp"
namespace caf {
/// Maps strings to values of type `V`, but unlike `std::map<std::string, V>`
/// accepts `string_view` for looking up keys efficiently.
/// accepts `std::string_view` for looking up keys efficiently.
template <class V>
class dictionary {
public:
......@@ -55,7 +55,7 @@ public:
using iterator_bool_pair = std::pair<iterator, bool>;
struct mapped_type_less {
bool operator()(const value_type& x, string_view y) const {
bool operator()(const value_type& x, std::string_view y) const {
return x.first < y;
}
......@@ -63,7 +63,7 @@ public:
return x.first < y.first;
}
bool operator()(string_view x, const value_type& y) const {
bool operator()(std::string_view x, const value_type& y) const {
return x < y.first;
}
};
......@@ -194,7 +194,7 @@ public:
}
template <class T>
iterator_bool_pair insert(string_view key, T&& value) {
iterator_bool_pair insert(std::string_view key, T&& value) {
return emplace(key, V{std::forward<T>(value)});
}
......@@ -202,7 +202,7 @@ public:
iterator emplace_hint(iterator hint, K&& key, T&& value) {
if (hint == end() || hint->first > key)
return xs_.emplace(copy(std::forward<K>(key)), V{std::forward<T>(value)})
.first;
.first;
if (hint->first == key)
return hint;
return xs_.emplace_hint(hint, copy(std::forward<K>(key)),
......@@ -210,7 +210,7 @@ public:
}
template <class T>
iterator insert(iterator hint, string_view key, T&& value) {
iterator insert(iterator hint, std::string_view key, T&& value) {
return emplace_hint(hint, key, std::forward<T>(value));
}
......@@ -219,7 +219,7 @@ public:
}
template <class T>
iterator_bool_pair insert_or_assign(string_view key, T&& value) {
iterator_bool_pair insert_or_assign(std::string_view key, T&& value) {
auto i = lower_bound(key);
if (i == end())
return xs_.emplace(copy(key), V{std::forward<T>(value)});
......@@ -231,7 +231,7 @@ public:
}
template <class T>
iterator insert_or_assign(iterator hint, string_view key, T&& value) {
iterator insert_or_assign(iterator hint, std::string_view key, T&& value) {
if (hint == end() || hint->first > key)
return insert_or_assign(key, std::forward<T>(value)).first;
hint = lower_bound(hint, key);
......@@ -244,56 +244,56 @@ public:
// -- lookup -----------------------------------------------------------------
bool contains(string_view key) const noexcept {
bool contains(std::string_view key) const noexcept {
auto i = lower_bound(key);
return !(i == end() || i->first != key);
}
size_t count(string_view key) const noexcept {
size_t count(std::string_view key) const noexcept {
return contains(key) ? 1u : 0u;
}
iterator find(string_view key) noexcept {
iterator find(std::string_view key) noexcept {
auto i = lower_bound(key);
return i != end() && i->first == key ? i : end();
}
const_iterator find(string_view key) const noexcept {
const_iterator find(std::string_view key) const noexcept {
auto i = lower_bound(key);
return i != end() && i->first == key ? i : end();
}
iterator lower_bound(string_view key) {
iterator lower_bound(std::string_view key) {
return lower_bound(begin(), key);
}
const_iterator lower_bound(string_view key) const {
const_iterator lower_bound(std::string_view key) const {
return lower_bound(begin(), key);
}
iterator upper_bound(string_view key) {
iterator upper_bound(std::string_view key) {
mapped_type_less cmp;
return std::upper_bound(begin(), end(), key, cmp);
}
const_iterator upper_bound(string_view key) const {
const_iterator upper_bound(std::string_view key) const {
mapped_type_less cmp;
return std::upper_bound(begin(), end(), key, cmp);
}
// -- element access ---------------------------------------------------------
mapped_type& operator[](string_view key) {
mapped_type& operator[](std::string_view key) {
return insert(key, mapped_type{}).first->second;
}
private:
iterator lower_bound(iterator from, string_view key) {
iterator lower_bound(iterator from, std::string_view key) {
mapped_type_less cmp;
return std::lower_bound(from, end(), key, cmp);
}
const_iterator lower_bound(const_iterator from, string_view key) const {
const_iterator lower_bound(const_iterator from, std::string_view key) const {
mapped_type_less cmp;
return std::lower_bound(from, end(), key, cmp);
}
......@@ -304,7 +304,7 @@ private:
}
// Copies the content of `str` into a new string.
static std::string copy(string_view str) {
static std::string copy(std::string_view str) {
return std::string{str.begin(), str.end()};
}
......
......@@ -10,6 +10,7 @@
#include <cstdint>
#include <string>
#include <string_view>
#include <type_traits>
#include "caf/default_enum_inspect.hpp"
......@@ -45,7 +46,7 @@ enum class exit_reason : uint8_t {
CAF_CORE_EXPORT std::string to_string(exit_reason);
/// @relates exit_reason
CAF_CORE_EXPORT bool from_string(string_view, exit_reason&);
CAF_CORE_EXPORT bool from_string(std::string_view, exit_reason&);
/// @relates exit_reason
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<exit_reason>,
......
......@@ -41,7 +41,7 @@ constexpr bool is_active(observable_state x) noexcept {
CAF_CORE_EXPORT std::string to_string(observable_state);
/// @relates observable_state
CAF_CORE_EXPORT bool from_string(string_view, observable_state&);
CAF_CORE_EXPORT bool from_string(std::string_view, observable_state&);
/// @relates observable_state
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<observable_state>,
......
......@@ -37,7 +37,7 @@ constexpr bool is_active(observer_state x) noexcept {
CAF_CORE_EXPORT std::string to_string(observer_state);
/// @relates observer_state
CAF_CORE_EXPORT bool from_string(string_view, observer_state&);
CAF_CORE_EXPORT bool from_string(std::string_view, observer_state&);
/// @relates observer_state
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<observer_state>,
......
......@@ -4,8 +4,10 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string_view>
#include <vector>
#include "caf/detail/core_export.hpp"
......@@ -25,7 +27,7 @@ template <class> class dictionary;
template <class> class expected;
template <class> class intrusive_cow_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 span;
template <class> class weak_intrusive_ptr;
......@@ -63,6 +65,7 @@ template <class...> class variant;
// -- classes ------------------------------------------------------------------
class [[deprecated("use std::string_view instead")]] string_view;
class [[nodiscard]] error;
class abstract_actor;
class abstract_group;
......@@ -117,7 +120,6 @@ class scheduled_actor;
class scoped_actor;
class serializer;
class skip_t;
class string_view;
class tracing_data;
class tracing_data_factory;
class type_id_list;
......@@ -146,16 +148,17 @@ struct unit_t;
// -- free template functions --------------------------------------------------
template <class T>
config_option make_config_option(string_view category, string_view name,
string_view description);
config_option make_config_option(std::string_view category,
std::string_view name,
std::string_view description);
template <class T>
config_option make_config_option(T& storage, string_view category,
string_view name, string_view description);
config_option make_config_option(T& storage, std::string_view category,
std::string_view name,
std::string_view description);
// -- enums --------------------------------------------------------------------
enum class byte : uint8_t;
enum class exit_reason : uint8_t;
enum class invoke_message_result;
enum class pec : uint8_t;
......@@ -164,9 +167,10 @@ enum class sec : uint8_t;
// -- aliases ------------------------------------------------------------------
using actor_id = uint64_t;
using byte_buffer = std::vector<byte>;
using byte_span = span<byte>;
using const_byte_span = span<const byte>;
using byte [[deprecated("use std::byte instead")]] = std::byte;
using byte_buffer = std::vector<std::byte>;
using byte_span = span<std::byte>;
using const_byte_span = span<const std::byte>;
using cow_string = basic_cow_string<char>;
using cow_u16string = basic_cow_string<char16_t>;
using cow_u32string = basic_cow_string<char32_t>;
......
......@@ -4,15 +4,15 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <type_traits>
#include "caf/byte.hpp"
#include "caf/detail/ieee_754.hpp"
#include "caf/inspector_access.hpp"
#include "caf/save_inspector_base.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
#include "caf/type_id.hpp"
namespace caf::hash {
......@@ -40,7 +40,7 @@ public:
return false;
}
constexpr bool begin_object(type_id_t, string_view) {
constexpr bool begin_object(type_id_t, std::string_view) {
return true;
}
......@@ -48,19 +48,19 @@ public:
return true;
}
bool begin_field(string_view) {
bool begin_field(std::string_view) {
return true;
}
bool begin_field(string_view, bool is_present) {
bool begin_field(std::string_view, bool is_present) {
return value(static_cast<uint8_t>(is_present));
}
bool begin_field(string_view, span<const type_id_t>, size_t index) {
bool begin_field(std::string_view, span<const type_id_t>, size_t index) {
return value(index);
}
bool begin_field(string_view, bool is_present, span<const type_id_t>,
bool begin_field(std::string_view, bool is_present, span<const type_id_t>,
size_t index) {
value(static_cast<uint8_t>(is_present));
if (is_present)
......@@ -112,7 +112,7 @@ public:
return true;
}
bool value(byte x) noexcept {
bool value(std::byte x) noexcept {
return value(static_cast<uint8_t>(x));
}
......@@ -129,13 +129,13 @@ public:
return value(detail::pack754(x));
}
bool value(string_view x) noexcept {
bool value(std::string_view x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(x.data());
append(begin, begin + x.size());
return true;
}
bool value(span<const byte> x) noexcept {
bool value(span<const std::byte> x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(x.data());
append(begin, begin + x.size());
return true;
......
......@@ -4,16 +4,16 @@
#pragma once
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/ieee_754.hpp"
#include "caf/save_inspector_base.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
#include "caf/type_id.hpp"
#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>
namespace caf::hash {
......@@ -27,7 +27,7 @@ public:
using super = save_inspector_base<sha1>;
/// Array type for storing a 160-bit hash.
using result_type = std::array<byte, hash_size>;
using result_type = std::array<std::byte, hash_size>;
sha1() noexcept;
......@@ -35,7 +35,7 @@ public:
return false;
}
constexpr bool begin_object(type_id_t, string_view) {
constexpr bool begin_object(type_id_t, std::string_view) {
return true;
}
......@@ -43,19 +43,19 @@ public:
return true;
}
bool begin_field(string_view) {
bool begin_field(std::string_view) {
return true;
}
bool begin_field(string_view, bool is_present) {
bool begin_field(std::string_view, bool is_present) {
return value(static_cast<uint8_t>(is_present));
}
bool begin_field(string_view, span<const type_id_t>, size_t index) {
bool begin_field(std::string_view, span<const type_id_t>, size_t index) {
return value(index);
}
bool begin_field(string_view, bool is_present, span<const type_id_t>,
bool begin_field(std::string_view, bool is_present, span<const type_id_t>,
size_t index) {
value(static_cast<uint8_t>(is_present));
if (is_present)
......@@ -120,13 +120,13 @@ public:
return value(detail::pack754(x));
}
bool value(string_view x) noexcept {
bool value(std::string_view x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(x.data());
append(begin, begin + x.size());
return true;
}
bool value(span<const byte> x) noexcept {
bool value(span<const std::byte> x) noexcept {
auto begin = reinterpret_cast<const uint8_t*>(x.data());
append(begin, begin + x.size());
return true;
......
......@@ -7,6 +7,7 @@
#include <chrono>
#include <cstddef>
#include <memory>
#include <string_view>
#include <tuple>
#include <utility>
......@@ -158,8 +159,8 @@ bool load(Inspector& f, T& x) {
}
template <class Inspector, class T, class IsValid, class SyncValue>
bool load_field(Inspector& f, string_view field_name, T& x, IsValid& is_valid,
SyncValue& sync_value) {
bool load_field(Inspector& f, std::string_view field_name, T& x,
IsValid& is_valid, SyncValue& sync_value) {
using impl = std::conditional_t<is_complete<inspector_access<T>>, // if
inspector_access<T>, // then
inspector_access_base<T>>; // else
......@@ -168,8 +169,9 @@ bool load_field(Inspector& f, string_view field_name, T& x, IsValid& is_valid,
template <class Inspector, class T, class IsValid, class SyncValue,
class SetFallback>
bool load_field(Inspector& f, string_view field_name, T& x, IsValid& is_valid,
SyncValue& sync_value, SetFallback& set_fallback) {
bool load_field(Inspector& f, std::string_view field_name, T& x,
IsValid& is_valid, SyncValue& sync_value,
SetFallback& set_fallback) {
using impl = std::conditional_t<is_complete<inspector_access<T>>, // if
inspector_access<T>, // then
inspector_access_base<T>>; // else
......@@ -263,7 +265,7 @@ bool save(Inspector& f, const T& x) {
}
template <class Inspector, class T>
bool save_field(Inspector& f, string_view field_name, T& x) {
bool save_field(Inspector& f, std::string_view field_name, T& x) {
using impl = std::conditional_t<is_complete<inspector_access<T>>, // if
inspector_access<T>, // then
inspector_access_base<T>>; // else
......@@ -271,8 +273,8 @@ bool save_field(Inspector& f, string_view field_name, T& x) {
}
template <class Inspector, class IsPresent, class Get>
bool save_field(Inspector& f, string_view field_name, IsPresent& is_present,
Get& get) {
bool save_field(Inspector& f, std::string_view field_name,
IsPresent& is_present, Get& get) {
using T = std::decay_t<decltype(get())>;
using impl = std::conditional_t<is_complete<inspector_access<T>>, // if
inspector_access<T>, // then
......@@ -304,6 +306,8 @@ struct optional_inspector_traits_base {
}
};
CAF_PUSH_DEPRECATED_WARNING
template <class T>
struct optional_inspector_traits;
......@@ -319,6 +323,8 @@ struct optional_inspector_traits<optional<T>> : optional_inspector_traits_base {
}
};
CAF_POP_WARNINGS
template <class T>
struct optional_inspector_traits<intrusive_ptr<T>>
: optional_inspector_traits_base {
......@@ -394,20 +400,20 @@ struct optional_inspector_access {
template <class Inspector>
static bool
save_field(Inspector& f, string_view field_name, container_type& x) {
save_field(Inspector& f, std::string_view field_name, container_type& x) {
auto is_present = [&x] { return static_cast<bool>(x); };
auto get = [&x]() -> decltype(auto) { return traits::deref_save(x); };
return detail::save_field(f, field_name, is_present, get);
}
template <class Inspector, class IsPresent, class Get>
static bool save_field(Inspector& f, string_view field_name,
static bool save_field(Inspector& f, std::string_view field_name,
IsPresent& is_present, Get& get) {
return detail::save_field(f, field_name, is_present, get);
}
template <class Inspector, class IsValid, class SyncValue>
static bool load_field(Inspector& f, string_view field_name,
static bool load_field(Inspector& f, std::string_view field_name,
container_type& x, IsValid& is_valid,
SyncValue& sync_value) {
traits::emplace(x);
......@@ -417,7 +423,7 @@ struct optional_inspector_access {
}
template <class Inspector, class IsValid, class SyncValue, class SetFallback>
static bool load_field(Inspector& f, string_view field_name,
static bool load_field(Inspector& f, std::string_view field_name,
container_type& x, IsValid& is_valid,
SyncValue& sync_value, SetFallback& set_fallback) {
traits::emplace(x);
......@@ -428,11 +434,15 @@ struct optional_inspector_access {
// -- inspection support for optional<T> ---------------------------------------
CAF_PUSH_DEPRECATED_WARNING
template <class T>
struct inspector_access<optional<T>> : optional_inspector_access<optional<T>> {
// nop
};
CAF_POP_WARNINGS
#ifdef CAF_HAS_STD_OPTIONAL
template <class T>
......@@ -539,7 +549,8 @@ struct variant_inspector_access {
}
template <class Inspector>
static bool save_field(Inspector& f, string_view field_name, value_type& x) {
static bool
save_field(Inspector& f, std::string_view field_name, value_type& x) {
auto g = [&f](auto& y) { return detail::save(f, y); };
return f.begin_field(field_name, make_span(traits::allowed_types),
traits::type_index(x)) //
......@@ -548,7 +559,7 @@ struct variant_inspector_access {
}
template <class Inspector, class IsPresent, class Get>
static bool save_field(Inspector& f, string_view field_name,
static bool save_field(Inspector& f, std::string_view field_name,
IsPresent& is_present, Get& get) {
auto allowed_types = make_span(traits::allowed_types);
if (is_present()) {
......@@ -564,7 +575,7 @@ struct variant_inspector_access {
}
template <class Inspector>
static bool load_variant_value(Inspector& f, string_view field_name,
static bool load_variant_value(Inspector& f, std::string_view field_name,
value_type& x, type_id_t runtime_type) {
auto res = false;
auto type_found = traits::load(runtime_type, [&](auto& tmp) {
......@@ -575,41 +586,43 @@ struct variant_inspector_access {
return;
});
if (!type_found)
f.emplace_error(sec::invalid_field_type, to_string(field_name));
f.emplace_error(sec::invalid_field_type, std::string{field_name});
return res;
}
template <class Inspector, class IsValid, class SyncValue>
static bool load_field(Inspector& f, string_view field_name, value_type& x,
IsValid& is_valid, SyncValue& sync_value) {
static bool load_field(Inspector& f, std::string_view field_name,
value_type& x, IsValid& is_valid,
SyncValue& sync_value) {
size_t type_index = std::numeric_limits<size_t>::max();
auto allowed_types = make_span(traits::allowed_types);
if (!f.begin_field(field_name, allowed_types, type_index))
return false;
if (type_index >= allowed_types.size()) {
f.emplace_error(sec::invalid_field_type, to_string(field_name));
f.emplace_error(sec::invalid_field_type, std::string{field_name});
return false;
}
auto runtime_type = allowed_types[type_index];
if (!load_variant_value(f, field_name, x, runtime_type))
return false;
if (!is_valid(x)) {
f.emplace_error(sec::field_invariant_check_failed, to_string(field_name));
f.emplace_error(sec::field_invariant_check_failed,
std::string{field_name});
return false;
}
if (!sync_value()) {
if (!f.get_error())
f.emplace_error(sec::field_value_synchronization_failed,
to_string(field_name));
std::string{field_name});
return false;
}
return f.end_field();
}
template <class Inspector, class IsValid, class SyncValue, class SetFallback>
static bool load_field(Inspector& f, string_view field_name, value_type& x,
IsValid& is_valid, SyncValue& sync_value,
SetFallback& set_fallback) {
static bool load_field(Inspector& f, std::string_view field_name,
value_type& x, IsValid& is_valid,
SyncValue& sync_value, SetFallback& set_fallback) {
bool is_present = false;
auto allowed_types = make_span(traits::allowed_types);
size_t type_index = std::numeric_limits<size_t>::max();
......@@ -617,7 +630,7 @@ struct variant_inspector_access {
return false;
if (is_present) {
if (type_index >= allowed_types.size()) {
f.emplace_error(sec::invalid_field_type, to_string(field_name));
f.emplace_error(sec::invalid_field_type, std::string{field_name});
return false;
}
auto runtime_type = allowed_types[type_index];
......@@ -625,13 +638,13 @@ struct variant_inspector_access {
return false;
if (!is_valid(x)) {
f.emplace_error(sec::field_invariant_check_failed,
to_string(field_name));
std::string{field_name});
return false;
}
if (!sync_value()) {
if (!f.get_error())
f.emplace_error(sec::field_value_synchronization_failed,
to_string(field_name));
std::string{field_name});
return false;
}
} else {
......
......@@ -4,9 +4,11 @@
#pragma once
#include <string>
#include <string_view>
#include "caf/detail/as_mutable_ref.hpp"
#include "caf/sec.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -15,18 +17,18 @@ template <class T>
struct inspector_access_base {
/// Loads a mandatory field from `f`.
template <class Inspector, class IsValid, class SyncValue>
static bool load_field(Inspector& f, string_view field_name, T& x,
static bool load_field(Inspector& f, std::string_view field_name, T& x,
IsValid& is_valid, SyncValue& sync_value) {
if (f.begin_field(field_name) && f.apply(x)) {
if (!is_valid(x)) {
f.emplace_error(sec::field_invariant_check_failed,
to_string(field_name));
std::string(field_name));
return false;
}
if (!sync_value()) {
if (!f.get_error())
f.emplace_error(sec::field_value_synchronization_failed,
to_string(field_name));
std::string(field_name));
return false;
}
return f.end_field();
......@@ -37,7 +39,7 @@ struct inspector_access_base {
/// Loads an optional field from `f`, calling `set_fallback` if the source
/// contains no value for `x`.
template <class Inspector, class IsValid, class SyncValue, class SetFallback>
static bool load_field(Inspector& f, string_view field_name, T& x,
static bool load_field(Inspector& f, std::string_view field_name, T& x,
IsValid& is_valid, SyncValue& sync_value,
SetFallback& set_fallback) {
bool is_present = false;
......@@ -48,13 +50,13 @@ struct inspector_access_base {
return false;
if (!is_valid(x)) {
f.emplace_error(sec::field_invariant_check_failed,
to_string(field_name));
std::string(field_name));
return false;
}
if (!sync_value()) {
if (!f.get_error())
f.emplace_error(sec::field_value_synchronization_failed,
to_string(field_name));
std::string(field_name));
return false;
}
return f.end_field();
......@@ -65,7 +67,7 @@ struct inspector_access_base {
/// Saves a mandatory field to `f`.
template <class Inspector>
static bool save_field(Inspector& f, string_view field_name, T& x) {
static bool save_field(Inspector& f, std::string_view field_name, T& x) {
return f.begin_field(field_name) //
&& f.apply(x) //
&& f.end_field();
......@@ -73,7 +75,7 @@ struct inspector_access_base {
/// Saves an optional field to `f`.
template <class Inspector, class IsPresent, class Get>
static bool save_field(Inspector& f, string_view field_name,
static bool save_field(Inspector& f, std::string_view field_name,
IsPresent& is_present, Get& get) {
if (is_present()) {
auto&& x = get();
......
......@@ -12,7 +12,6 @@
#include "caf/detail/type_traits.hpp"
#include "caf/fwd.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
namespace caf {
......
......@@ -121,6 +121,6 @@ CAF_CORE_EXPORT std::string to_string(const ipv4_address& x);
/// Tries to parse the content of `str` into `dest`.
/// @relates ipv4_address
CAF_CORE_EXPORT error parse(string_view str, ipv4_address& dest);
CAF_CORE_EXPORT error parse(std::string_view str, ipv4_address& dest);
} // namespace caf
......@@ -119,6 +119,6 @@ private:
};
};
CAF_CORE_EXPORT error parse(string_view str, ipv6_address& dest);
CAF_CORE_EXPORT error parse(std::string_view str, ipv6_address& dest);
} // namespace caf
......@@ -7,8 +7,8 @@
#include "caf/deserializer.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/json.hpp"
#include "caf/string_view.hpp"
#include <string_view>
#include <variant>
namespace caf {
......@@ -56,7 +56,7 @@ public:
}
};
using json_key = string_view;
using json_key = std::string_view;
using value_type
= std::variant<const detail::json::value*, const detail::json::object*,
......@@ -82,7 +82,7 @@ public:
// -- constants --------------------------------------------------------------
/// The value value for `field_type_suffix()`.
static constexpr string_view field_type_suffix_default = "-type";
static constexpr std::string_view field_type_suffix_default = "-type";
// -- constructors, destructors, and assignment operators --------------------
......@@ -103,12 +103,12 @@ public:
/// Returns the suffix for generating type annotation fields for variant
/// fields. For example, CAF inserts field called "@foo${field_type_suffix}"
/// for a variant field called "foo".
[[nodiscard]] string_view field_type_suffix() const noexcept {
[[nodiscard]] std::string_view field_type_suffix() const noexcept {
return field_type_suffix_;
}
/// Configures whether the writer omits empty fields.
void field_type_suffix(string_view suffix) noexcept {
void field_type_suffix(std::string_view suffix) noexcept {
field_type_suffix_ = suffix;
}
......@@ -121,7 +121,7 @@ public:
/// Hence, the buffer pointed to by the string view must remain valid
/// until either destroying this reader or calling `reset`.
/// @note Implicitly calls `reset`.
bool load(string_view json_text);
bool load(std::string_view json_text);
/// Reverts the state of the reader back to where it was after calling `load`.
/// @post The reader is ready for attempting to deserialize another
......@@ -135,20 +135,20 @@ public:
bool fetch_next_object_type(type_id_t& type) override;
bool fetch_next_object_name(string_view& type_name) override;
bool fetch_next_object_name(std::string_view& type_name) override;
bool begin_object(type_id_t type, string_view name) override;
bool begin_object(type_id_t type, std::string_view name) override;
bool end_object() override;
bool begin_field(string_view) override;
bool begin_field(std::string_view) override;
bool begin_field(string_view name, bool& is_present) override;
bool begin_field(std::string_view name, bool& is_present) override;
bool begin_field(string_view name, span<const type_id_t> types,
bool begin_field(std::string_view name, span<const type_id_t> types,
size_t& index) override;
bool begin_field(string_view name, bool& is_present,
bool begin_field(std::string_view name, bool& is_present,
span<const type_id_t> types, size_t& index) override;
bool end_field() override;
......@@ -169,7 +169,7 @@ public:
bool end_associative_array() override;
bool value(byte& x) override;
bool value(std::byte& x) override;
bool value(bool& x) override;
......@@ -201,7 +201,7 @@ public:
bool value(std::u32string& x) override;
bool value(span<byte> x) override;
bool value(span<std::byte> x) override;
private:
[[nodiscard]] position pos() const noexcept;
......@@ -210,7 +210,7 @@ private:
std::string current_field_name();
std::string mandatory_field_missing_str(string_view name);
std::string mandatory_field_missing_str(std::string_view name);
template <bool PopOrAdvanceOnSuccess, class F>
bool consume(const char* fun_name, F f);
......@@ -243,10 +243,10 @@ private:
detail::json::value* root_ = nullptr;
string_view field_type_suffix_ = field_type_suffix_default;
std::string_view field_type_suffix_ = field_type_suffix_default;
/// Keeps track of the current field for better debugging output.
std::vector<string_view> field_;
std::vector<std::string_view> field_;
};
} // namespace caf
......@@ -42,7 +42,7 @@ public:
static constexpr bool skip_object_type_annotation_default = false;
/// The value value for `field_type_suffix()`.
static constexpr string_view field_type_suffix_default = "-type";
static constexpr std::string_view field_type_suffix_default = "-type";
// -- constructors, destructors, and assignment operators --------------------
......@@ -59,7 +59,7 @@ public:
/// Returns a string view into the internal buffer.
/// @warning This view becomes invalid when calling any non-const member
/// function on the writer object.
[[nodiscard]] string_view str() const noexcept {
[[nodiscard]] std::string_view str() const noexcept {
return {buf_.data(), buf_.size()};
}
......@@ -106,12 +106,12 @@ public:
/// Returns the suffix for generating type annotation fields for variant
/// fields. For example, CAF inserts field called "@foo${field_type_suffix}"
/// for a variant field called "foo".
[[nodiscard]] string_view field_type_suffix() const noexcept {
[[nodiscard]] std::string_view field_type_suffix() const noexcept {
return field_type_suffix_;
}
/// Configures whether the writer omits empty fields.
void field_type_suffix(string_view suffix) noexcept {
void field_type_suffix(std::string_view suffix) noexcept {
field_type_suffix_ = suffix;
}
......@@ -124,18 +124,18 @@ public:
// -- overrides --------------------------------------------------------------
bool begin_object(type_id_t type, string_view name) override;
bool begin_object(type_id_t type, std::string_view name) override;
bool end_object() override;
bool begin_field(string_view) override;
bool begin_field(std::string_view) override;
bool begin_field(string_view name, bool is_present) override;
bool begin_field(std::string_view name, bool is_present) override;
bool begin_field(string_view name, span<const type_id_t> types,
bool begin_field(std::string_view name, span<const type_id_t> types,
size_t index) override;
bool begin_field(string_view name, bool is_present,
bool begin_field(std::string_view name, bool is_present,
span<const type_id_t> types, size_t index) override;
bool end_field() override;
......@@ -156,7 +156,7 @@ public:
bool end_associative_array() override;
bool value(byte x) override;
bool value(std::byte x) override;
bool value(bool x) override;
......@@ -182,13 +182,13 @@ public:
bool value(long double x) override;
bool value(string_view x) override;
bool value(std::string_view x) override;
bool value(const std::u16string& x) override;
bool value(const std::u32string& x) override;
bool value(span<const byte> x) override;
bool value(span<const std::byte> x) override;
private:
// -- implementation details -------------------------------------------------
......@@ -242,7 +242,7 @@ private:
}
// Adds `str` to the output buffer.
void add(string_view str) {
void add(std::string_view str) {
buf_.insert(buf_.end(), str.begin(), str.end());
}
......@@ -280,7 +280,7 @@ private:
// Configures whether we omit the top-level '@type' annotation.
bool skip_object_type_annotation_ = false;
string_view field_type_suffix_ = field_type_suffix_default;
std::string_view field_type_suffix_ = field_type_suffix_default;
};
} // namespace caf
......@@ -4,6 +4,7 @@
#pragma once
#include <string_view>
#include <type_traits>
#include <utility>
......@@ -11,7 +12,6 @@
#include "caf/detail/core_export.hpp"
#include "caf/error.hpp"
#include "caf/inspector_access.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -68,7 +68,7 @@ public:
template <class T, class U, class Predicate>
struct field_with_invariant_and_fallback_t {
string_view field_name;
std::string_view field_name;
T* val;
U fallback;
Predicate predicate;
......@@ -83,7 +83,7 @@ public:
template <class T, class U>
struct field_with_fallback_t {
string_view field_name;
std::string_view field_name;
T* val;
U fallback;
......@@ -107,7 +107,7 @@ public:
template <class T, class Predicate>
struct field_with_invariant_t {
string_view field_name;
std::string_view field_name;
T* val;
Predicate predicate;
......@@ -130,7 +130,7 @@ public:
template <class T>
struct field_t {
string_view field_name;
std::string_view field_name;
T* val;
template <class Inspector>
......@@ -158,7 +158,7 @@ public:
template <class T, class Set, class U, class Predicate>
struct virt_field_with_invariant_and_fallback_t {
string_view field_name;
std::string_view field_name;
Set set;
U fallback;
Predicate predicate;
......@@ -174,7 +174,7 @@ public:
template <class T, class Set, class U>
struct virt_field_with_fallback_t {
string_view field_name;
std::string_view field_name;
Set set;
U fallback;
......@@ -200,7 +200,7 @@ public:
template <class T, class Set, class Predicate>
struct virt_field_with_invariant_t {
string_view field_name;
std::string_view field_name;
Set set;
Predicate predicate;
......@@ -224,7 +224,7 @@ public:
template <class T, class Set>
struct virt_field_t {
string_view field_name;
std::string_view field_name;
Set set;
template <class Inspector>
......@@ -255,7 +255,7 @@ public:
template <class T, class Reset, class Set>
struct optional_virt_field_t {
string_view field_name;
std::string_view field_name;
Reset reset;
Set set;
......@@ -273,7 +273,7 @@ public:
template <class Inspector, class LoadCallback>
struct object_with_load_callback_t {
type_id_t object_type;
string_view object_name;
std::string_view object_name;
Inspector* f;
LoadCallback load_callback;
......@@ -296,7 +296,7 @@ public:
return f->end_object();
}
auto pretty_name(string_view name) && {
auto pretty_name(std::string_view name) && {
return object_t{object_type, name, f};
}
......@@ -309,7 +309,7 @@ public:
template <class Inspector>
struct object_t {
type_id_t object_type;
string_view object_name;
std::string_view object_name;
Inspector* f;
template <class... Fields>
......@@ -319,7 +319,7 @@ public:
&& f->end_object();
}
auto pretty_name(string_view name) && {
auto pretty_name(std::string_view name) && {
return object_t{object_type, name, f};
}
......@@ -342,13 +342,13 @@ public:
// -- factory functions ------------------------------------------------------
template <class T>
static auto field(string_view name, T& x) {
static auto field(std::string_view name, T& x) {
static_assert(!std::is_const<T>::value);
return field_t<T>{name, &x};
}
template <class Get, class Set>
static auto field(string_view name, Get get, Set set) {
static auto field(std::string_view name, Get get, Set set) {
using field_type = std::decay_t<decltype(get())>;
using setter_result = decltype(set(std::declval<field_type&&>()));
if constexpr (std::is_same<setter_result, error>::value
......@@ -368,7 +368,7 @@ public:
template <class IsPresent, class Get, class Reset, class Set>
static auto
field(string_view name, IsPresent&&, Get&& get, Reset reset, Set set) {
field(std::string_view name, IsPresent&&, Get&& get, Reset reset, Set set) {
using field_type = std::decay_t<decltype(get())>;
using setter_result = decltype(set(std::declval<field_type&&>()));
if constexpr (std::is_same<setter_result, error>::value
......
......@@ -29,7 +29,7 @@ public:
type_name_or_anonymous<T>(), dptr()};
}
constexpr auto virtual_object(string_view type_name) noexcept {
constexpr auto virtual_object(std::string_view type_name) noexcept {
return super::object_t<Subtype>{invalid_type_id, type_name, dptr()};
}
......
......@@ -8,6 +8,7 @@
#include <fstream>
#include <iostream>
#include <sstream>
#include <string_view>
#include <thread>
#include <type_traits>
#include <typeinfo>
......@@ -28,7 +29,6 @@
#include "caf/intrusive/fifo_inbox.hpp"
#include "caf/intrusive/singly_linked.hpp"
#include "caf/ref_counted.hpp"
#include "caf/string_view.hpp"
#include "caf/timestamp.hpp"
#include "caf/unifyn.hpp"
......@@ -99,9 +99,9 @@ public:
event& operator=(const event&) = default;
event(unsigned lvl, unsigned line, string_view cat, string_view full_fun,
string_view fun, string_view fn, std::string msg, std::thread::id t,
actor_id a, timestamp ts);
event(unsigned lvl, unsigned line, std::string_view cat,
std::string_view full_fun, std::string_view fun, std::string_view fn,
std::string msg, std::thread::id t, actor_id a, timestamp ts);
// -- member variables -----------------------------------------------------
......@@ -112,16 +112,16 @@ public:
unsigned line_number;
/// Name of the category (component) logging the event.
string_view category_name;
std::string_view category_name;
/// Name of the current function as reported by `__PRETTY_FUNCTION__`.
string_view pretty_fun;
std::string_view pretty_fun;
/// Name of the current function as reported by `__func__`.
string_view simple_fun;
std::string_view simple_fun;
/// Name of the current file.
string_view file_name;
std::string_view file_name;
/// User-provided message.
std::string message;
......@@ -181,7 +181,7 @@ public:
line_builder& operator<<(const std::string& str);
line_builder& operator<<(string_view str);
line_builder& operator<<(std::string_view str);
line_builder& operator<<(const char* str);
......@@ -213,7 +213,7 @@ public:
/// Returns whether the logger is configured to accept input for given
/// component and log level.
bool accepts(unsigned level, string_view component_name);
bool accepts(unsigned level, std::string_view component_name);
/// Returns the output format used for the log file.
const line_format& file_format() const {
......@@ -253,7 +253,7 @@ public:
static line_format parse_format(const std::string& format_str);
/// Skips path in `filename`.
static string_view skip_path(string_view filename);
static std::string_view skip_path(std::string_view filename);
// -- utility functions ------------------------------------------------------
......
......@@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <string_view>
#include "caf/config_option.hpp"
#include "caf/config_value.hpp"
......@@ -13,7 +14,6 @@
#include "caf/expected.hpp"
#include "caf/fwd.hpp"
#include "caf/pec.hpp"
#include "caf/string_view.hpp"
namespace caf::detail {
......@@ -53,15 +53,17 @@ namespace caf {
/// Creates a config option that synchronizes with `storage`.
template <class T>
config_option make_config_option(string_view category, string_view name,
string_view description) {
config_option make_config_option(std::string_view category,
std::string_view name,
std::string_view description) {
return {category, name, description, detail::option_meta_state_instance<T>()};
}
/// Creates a config option that synchronizes with `storage`.
template <class T>
config_option make_config_option(T& storage, string_view category,
string_view name, string_view description) {
config_option make_config_option(T& storage, std::string_view category,
std::string_view name,
std::string_view description) {
return {category, name, description, detail::option_meta_state_instance<T>(),
std::addressof(storage)};
}
......@@ -70,7 +72,7 @@ config_option make_config_option(T& storage, string_view category,
// Inverts the value when writing to `storage`.
CAF_CORE_EXPORT config_option
make_negated_config_option(bool& storage, string_view category,
string_view name, string_view description);
make_negated_config_option(bool& storage, std::string_view category,
std::string_view name, std::string_view description);
} // namespace caf
......@@ -72,8 +72,8 @@ public:
void assign(message_handler what);
/// Runs this handler and returns its (optional) result.
optional<message> operator()(message& arg) {
return (impl_) ? impl_->invoke(arg) : none;
std::optional<message> operator()(message& arg) {
return (impl_) ? impl_->invoke(arg) : std::nullopt;
}
/// Runs this handler with callback.
......
......@@ -51,7 +51,7 @@ public:
static bool valid(const host_id_type& x) noexcept;
static bool can_parse(string_view str) noexcept;
static bool can_parse(std::string_view str) noexcept;
static node_id local(const actor_system_config&);
......@@ -153,7 +153,7 @@ public:
void swap(node_id& other) noexcept;
/// Returns whether `parse` would produce a valid node ID.
static bool can_parse(string_view str) noexcept;
static bool can_parse(std::string_view str) noexcept;
// -- friend functions -------------------------------------------------------
......@@ -279,11 +279,11 @@ CAF_CORE_EXPORT node_id make_node_id(
/// @param process_id System-wide unique process identifier.
/// @param host_hash Unique node ID as hexadecimal string representation.
/// @relates node_id
CAF_CORE_EXPORT optional<node_id> make_node_id(uint32_t process_id,
string_view host_hash);
CAF_CORE_EXPORT std::optional<node_id> make_node_id(uint32_t process_id,
std::string_view host_hash);
/// @relates node_id
CAF_CORE_EXPORT error parse(string_view str, node_id& dest);
CAF_CORE_EXPORT error parse(std::string_view str, node_id& dest);
} // namespace caf
......
......@@ -268,6 +268,8 @@ private:
bool m_value;
};
CAF_PUSH_DEPRECATED_WARNING
/// @relates optional
template <class T>
auto to_string(const optional<T>& x)
......@@ -476,4 +478,6 @@ bool operator>=(const T& lhs, const optional<T>& rhs) {
return !rhs || !(lhs < *rhs);
}
CAF_POP_WARNINGS
} // namespace caf
......@@ -6,10 +6,10 @@
#include <cctype>
#include <cstdint>
#include <string_view>
#include "caf/fwd.hpp"
#include "caf/pec.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -137,6 +137,6 @@ auto make_error(const parser_state<Iterator, Sentinel>& ps, Ts&&... xs)
}
/// Specialization for parsers operating on string views.
using string_parser_state = parser_state<string_view::iterator>;
using string_parser_state = parser_state<std::string_view::iterator>;
} // namespace caf
......@@ -72,7 +72,7 @@ enum class pec : uint8_t {
CAF_CORE_EXPORT std::string to_string(pec);
/// @relates pec
CAF_CORE_EXPORT bool from_string(string_view, pec&);
CAF_CORE_EXPORT bool from_string(std::string_view, pec&);
/// @relates pec
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<pec>, pec&);
......
......@@ -4,6 +4,7 @@
#pragma once
#include <string_view>
#include <utility>
#include "caf/detail/as_mutable_ref.hpp"
......@@ -11,7 +12,6 @@
#include "caf/error.hpp"
#include "caf/inspector_access.hpp"
#include "caf/sec.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -68,7 +68,7 @@ public:
template <class T, class U>
struct field_with_fallback_t {
string_view field_name;
std::string_view field_name;
T* val;
U fallback;
......@@ -87,7 +87,7 @@ public:
template <class T>
struct field_t {
string_view field_name;
std::string_view field_name;
T* val;
template <class Inspector>
......@@ -110,7 +110,7 @@ public:
template <class T, class Get, class U>
struct virt_field_with_fallback_t {
string_view field_name;
std::string_view field_name;
Get get;
U fallback;
......@@ -128,7 +128,7 @@ public:
template <class T, class Get>
struct virt_field_t {
string_view field_name;
std::string_view field_name;
Get get;
template <class Inspector>
......@@ -154,7 +154,7 @@ public:
template <class T, class IsPresent, class Get>
struct optional_virt_field_t {
string_view field_name;
std::string_view field_name;
IsPresent is_present;
Get get;
......@@ -169,7 +169,7 @@ public:
template <class Inspector, class SaveCallback>
struct object_with_save_callback_t {
type_id_t object_type;
string_view object_name;
std::string_view object_name;
Inspector* f;
SaveCallback save_callback;
......@@ -192,7 +192,7 @@ public:
return f->end_object();
}
auto pretty_name(string_view name) && {
auto pretty_name(std::string_view name) && {
return object_t{name, f};
}
......@@ -205,7 +205,7 @@ public:
template <class Inspector>
struct object_t {
type_id_t object_type;
string_view object_name;
std::string_view object_name;
Inspector* f;
template <class... Fields>
......@@ -215,7 +215,7 @@ public:
&& f->end_object();
}
auto pretty_name(string_view name) && {
auto pretty_name(std::string_view name) && {
return object_t{object_type, name, f};
}
......@@ -238,19 +238,20 @@ public:
// -- factory functions ------------------------------------------------------
template <class T>
static auto field(string_view name, T& x) {
static auto field(std::string_view name, T& x) {
static_assert(!std::is_const<T>::value);
return field_t<T>{name, std::addressof(x)};
}
template <class Get, class Set>
static auto field(string_view name, Get get, Set&&) {
static auto field(std::string_view name, Get get, Set&&) {
using field_type = std::decay_t<decltype(get())>;
return virt_field_t<field_type, Get>{name, get};
}
template <class IsPresent, class Get, class... Ts>
static auto field(string_view name, IsPresent is_present, Get get, Ts&&...) {
static auto
field(std::string_view name, IsPresent is_present, Get get, Ts&&...) {
using field_type = std::decay_t<decltype(get())>;
return optional_virt_field_t<field_type, IsPresent, Get>{
name,
......
......@@ -4,6 +4,8 @@
#pragma once
#include <string_view>
#include "caf/inspector_access.hpp"
#include "caf/save_inspector.hpp"
......@@ -24,7 +26,7 @@ public:
type_name_or_anonymous<T>(), dptr()};
}
constexpr auto virtual_object(string_view type_name) noexcept {
constexpr auto virtual_object(std::string_view type_name) noexcept {
return super::object_t<Subtype>{invalid_type_id, type_name, dptr()};
}
......
......@@ -182,7 +182,7 @@ enum class sec : uint8_t {
CAF_CORE_EXPORT std::string to_string(sec);
/// @relates sec
CAF_CORE_EXPORT bool from_string(string_view, sec&);
CAF_CORE_EXPORT bool from_string(std::string_view, sec&);
/// @relates sec
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<sec>, sec&);
......
......@@ -7,18 +7,17 @@
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
#include "caf/save_inspector_base.hpp"
#include "caf/sec.hpp"
#include "caf/span.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -53,20 +52,20 @@ public:
/// Begins processing of an object. May save the type information to the
/// underlying storage to allow a @ref deserializer to retrieve and check the
/// type information for data formats that provide deserialization.
virtual bool begin_object(type_id_t type, string_view name) = 0;
virtual bool begin_object(type_id_t type, std::string_view name) = 0;
/// Ends processing of an object.
virtual bool end_object() = 0;
virtual bool begin_field(string_view) = 0;
virtual bool begin_field(std::string_view) = 0;
virtual bool begin_field(string_view name, bool is_present) = 0;
virtual bool begin_field(std::string_view name, bool is_present) = 0;
virtual bool
begin_field(string_view name, span<const type_id_t> types, size_t index)
begin_field(std::string_view name, span<const type_id_t> types, size_t index)
= 0;
virtual bool begin_field(string_view name, bool is_present,
virtual bool begin_field(std::string_view name, bool is_present,
span<const type_id_t> types, size_t index)
= 0;
......@@ -104,7 +103,7 @@ public:
/// Adds `x` to the output.
/// @param x A value for a builtin type.
/// @returns `true` on success, `false` otherwise.
virtual bool value(byte x) = 0;
virtual bool value(std::byte x) = 0;
/// @copydoc value
virtual bool value(bool x) = 0;
......@@ -149,7 +148,7 @@ public:
virtual bool value(long double x) = 0;
/// @copydoc value
virtual bool value(string_view x) = 0;
virtual bool value(std::string_view x) = 0;
/// @copydoc value
virtual bool value(const std::u16string& x) = 0;
......@@ -160,13 +159,13 @@ public:
/// Adds `x` as raw byte block to the output.
/// @param x The byte sequence.
/// @returns A non-zero error code on failure, `sec::success` otherwise.
virtual bool value(span<const byte> x) = 0;
virtual bool value(span<const std::byte> x) = 0;
using super::list;
/// Adds each boolean in `xs` to the output. Derived classes can override this
/// member function to pack the booleans, for example to avoid using one byte
/// for each value in a binary output format.
/// member function to pack the booleans, for example to avoid using one
/// byte for each value in a binary output format.
virtual bool list(const std::vector<bool>& xs);
protected:
......
......@@ -4,13 +4,13 @@
#pragma once
#include <string_view>
#include "caf/config_value.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/move_if_not_ptr.hpp"
#include "caf/dictionary.hpp"
#include "caf/optional.hpp"
#include "caf/raise_error.hpp"
#include "caf/string_view.hpp"
#include "caf/sum_type.hpp"
namespace caf {
......@@ -25,12 +25,12 @@ CAF_CORE_EXPORT std::string to_string(const settings& xs);
/// Tries to retrieve the value associated to `name` from `xs`.
/// @relates config_value
CAF_CORE_EXPORT const config_value* get_if(const settings* xs,
string_view name);
std::string_view name);
/// Tries to retrieve the value associated to `name` from `xs`.
/// @relates config_value
template <class T>
auto get_if(const settings* xs, string_view name) {
auto get_if(const settings* xs, std::string_view name) {
auto value = get_if(xs, name);
using result_type = decltype(get_if<T>(value));
return value ? get_if<T>(value) : result_type{};
......@@ -39,7 +39,7 @@ auto get_if(const settings* xs, string_view name) {
/// Returns whether `xs` associates a value of type `T` to `name`.
/// @relates config_value
template <class T>
bool holds_alternative(const settings& xs, string_view name) {
bool holds_alternative(const settings& xs, std::string_view name) {
if (auto value = get_if(&xs, name))
return holds_alternative<T>(*value);
else
......@@ -49,7 +49,7 @@ bool holds_alternative(const settings& xs, string_view name) {
/// Retrieves the value associated to `name` from `xs`.
/// @relates actor_system_config
template <class T>
T get(const settings& xs, string_view name) {
T get(const settings& xs, std::string_view name) {
auto result = get_if<T>(&xs, name);
CAF_ASSERT(result);
return detail::move_if_not_ptr(result);
......@@ -58,7 +58,7 @@ T get(const settings& xs, string_view name) {
/// Retrieves the value associated to `name` from `xs` or returns `fallback`.
/// @relates actor_system_config
template <class To = get_or_auto_deduce, class Fallback>
auto get_or(const settings& xs, string_view name, Fallback&& fallback) {
auto get_or(const settings& xs, std::string_view name, Fallback&& fallback) {
if (auto ptr = get_if(&xs, name)) {
return get_or<To>(*ptr, std::forward<Fallback>(fallback));
} else if constexpr (std::is_same<To, get_or_auto_deduce>::value) {
......@@ -73,7 +73,7 @@ auto get_or(const settings& xs, string_view name, Fallback&& fallback) {
/// type `T`.
/// @relates actor_system_config
template <class T>
expected<T> get_as(const settings& xs, string_view name) {
expected<T> get_as(const settings& xs, std::string_view name) {
if (auto ptr = get_if(&xs, name))
return get_as<T>(*ptr);
else
......@@ -81,7 +81,7 @@ expected<T> get_as(const settings& xs, string_view name) {
}
/// @private
CAF_CORE_EXPORT config_value& put_impl(settings& dict, string_view name,
CAF_CORE_EXPORT config_value& put_impl(settings& dict, std::string_view name,
config_value& value);
/// Converts `value` to a `config_value` and assigns it to `key`.
......@@ -89,7 +89,7 @@ CAF_CORE_EXPORT config_value& put_impl(settings& dict, string_view name,
/// @param key Human-readable nested keys in the form `category.key`.
/// @param value New value for given `key`.
template <class T>
config_value& put(settings& dict, string_view key, T&& value) {
config_value& put(settings& dict, std::string_view key, T&& value) {
config_value tmp{std::forward<T>(value)};
return put_impl(dict, key, tmp);
}
......@@ -100,7 +100,7 @@ config_value& put(settings& dict, string_view key, T&& value) {
/// @param key Human-readable nested keys in the form `category.key`.
/// @param value New value for given `key`.
template <class T>
void put_missing(settings& xs, string_view key, T&& value) {
void put_missing(settings& xs, std::string_view key, T&& value) {
if (get_if(&xs, key) != nullptr)
return;
config_value tmp{std::forward<T>(value)};
......
......@@ -5,9 +5,9 @@
#pragma once
#include <array>
#include <cstddef>
#include <type_traits>
#include "caf/byte.hpp"
#include "caf/detail/type_traits.hpp"
namespace caf {
......@@ -197,13 +197,13 @@ auto cend(const span<T>& xs) -> decltype(xs.cend()) {
}
template <class T>
span<const byte> as_bytes(span<T> xs) {
return {reinterpret_cast<const byte*>(xs.data()), xs.size_bytes()};
span<const std::byte> as_bytes(span<T> xs) {
return {reinterpret_cast<const std::byte*>(xs.data()), xs.size_bytes()};
}
template <class T>
span<byte> as_writable_bytes(span<T> xs) {
return {reinterpret_cast<byte*>(xs.data()), xs.size_bytes()};
span<std::byte> as_writable_bytes(span<T> xs) {
return {reinterpret_cast<std::byte*>(xs.data()), xs.size_bytes()};
}
/// Convenience function to make using `caf::span` more convenient without the
......
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#pragma once
namespace caf {
template <class Result = void>
struct static_visitor {
using result_type = Result;
};
} // namespace caf
......@@ -8,38 +8,43 @@
#include <limits>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
#include "caf/config.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/string_view.hpp"
namespace caf {
// provide boost::split compatible interface
constexpr string_view is_any_of(string_view arg) noexcept {
constexpr std::string_view is_any_of(std::string_view arg) noexcept {
return arg;
}
constexpr bool token_compress_on = false;
CAF_CORE_EXPORT void split(std::vector<std::string>& result, string_view str,
string_view delims, bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<std::string>& result,
std::string_view str, std::string_view delims,
bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<string_view>& result, string_view str,
string_view delims, bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<std::string_view>& result,
std::string_view str, std::string_view delims,
bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<std::string>& result, string_view str,
char delim, bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<std::string>& result,
std::string_view str, char delim,
bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<string_view>& result, string_view str,
char delim, bool keep_all = true);
CAF_CORE_EXPORT void split(std::vector<std::string_view>& result,
std::string_view str, char delim,
bool keep_all = true);
template <class InputIterator>
std::string join(InputIterator first, InputIterator last, string_view glue) {
std::string
join(InputIterator first, InputIterator last, std::string_view glue) {
if (first == last)
return {};
std::ostringstream oss;
......@@ -50,18 +55,18 @@ std::string join(InputIterator first, InputIterator last, string_view glue) {
}
template <class Container>
std::string join(const Container& c, string_view glue) {
std::string join(const Container& c, std::string_view glue) {
return join(c.begin(), c.end(), glue);
}
/// Replaces all occurrences of `what` by `with` in `str`.
CAF_CORE_EXPORT void
replace_all(std::string& str, string_view what, string_view with);
CAF_CORE_EXPORT void replace_all(std::string& str, std::string_view what,
std::string_view with);
/// Returns whether `str` begins with `prefix`.
CAF_CORE_EXPORT bool starts_with(string_view str, string_view prefix);
CAF_CORE_EXPORT bool starts_with(std::string_view str, std::string_view prefix);
/// Returns whether `str` ends with `suffix`.
CAF_CORE_EXPORT bool ends_with(string_view str, string_view suffix);
CAF_CORE_EXPORT bool ends_with(std::string_view str, std::string_view suffix);
} // namespace caf
......@@ -12,8 +12,10 @@
#include <string>
#include <type_traits>
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
namespace caf {
......@@ -200,8 +202,8 @@ public:
int compare(size_type pos, size_type n, const_pointer str) const noexcept;
int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) const
noexcept;
int compare(size_type pos1, size_type n1, const_pointer s,
size_type n2) const noexcept;
size_type find(string_view str, size_type pos = 0) const noexcept;
......@@ -223,8 +225,8 @@ public:
size_type find_first_of(value_type ch, size_type pos = 0) const noexcept;
size_type find_first_of(const_pointer str, size_type pos, size_type n) const
noexcept;
size_type find_first_of(const_pointer str, size_type pos,
size_type n) const noexcept;
size_type find_first_of(const_pointer str, size_type pos = 0) const noexcept;
......@@ -232,40 +234,42 @@ public:
size_type find_last_of(value_type ch, size_type pos = npos) const noexcept;
size_type find_last_of(const_pointer str, size_type pos, size_type n) const
noexcept;
size_type find_last_of(const_pointer str, size_type pos,
size_type n) const noexcept;
size_type find_last_of(const_pointer str, size_type pos = npos) const
noexcept;
size_type find_last_of(const_pointer str,
size_type pos = npos) const noexcept;
size_type find_first_not_of(string_view str, size_type pos = 0) const
noexcept;
size_type find_first_not_of(string_view str,
size_type pos = 0) const noexcept;
size_type find_first_not_of(value_type ch, size_type pos = 0) const noexcept;
size_type find_first_not_of(const_pointer str, size_type pos,
size_type n) const noexcept;
size_type find_first_not_of(const_pointer str, size_type pos = 0) const
noexcept;
size_type find_first_not_of(const_pointer str,
size_type pos = 0) const noexcept;
size_type find_last_not_of(string_view str, size_type pos = npos) const
noexcept;
size_type find_last_not_of(string_view str,
size_type pos = npos) const noexcept;
size_type find_last_not_of(value_type ch, size_type pos = npos) const
noexcept;
size_type find_last_not_of(value_type ch,
size_type pos = npos) const noexcept;
size_type find_last_not_of(const_pointer str, size_type pos,
size_type n) const noexcept;
size_type find_last_not_of(const_pointer str, size_type pos = npos) const
noexcept;
size_type find_last_not_of(const_pointer str,
size_type pos = npos) const noexcept;
private:
const char* data_;
size_t size_;
};
CAF_PUSH_DEPRECATED_WARNING
/// @relates string_view
inline std::string to_string(string_view x) {
return std::string{x.begin(), x.end()};
......@@ -286,3 +290,5 @@ namespace std {
CAF_CORE_EXPORT std::ostream& operator<<(std::ostream& out, caf::string_view);
} // namespace std
CAF_POP_WARNINGS
......@@ -38,8 +38,8 @@ struct sum_type_index {
template <class Trait, class T>
struct sum_type_index<Trait, T, true> {
static constexpr int value =
detail::tl_index_of<typename Trait::types, T>::value;
static constexpr int value
= detail::tl_index_of<typename Trait::types, T>::value;
};
template <class Trait, class T>
......@@ -48,7 +48,6 @@ make_sum_type_token() {
return {};
}
/// Returns a reference to the value of a sum type.
/// @pre `holds_alternative<T>(x)`
template <class T, class U, class Trait = sum_type_access<U>>
......@@ -60,7 +59,7 @@ auto get(U& x) -> decltype(Trait::get(x, make_sum_type_token<Trait, T>())) {
/// @pre `holds_alternative<T>(x)`
template <class T, class U, class Trait = sum_type_access<U>>
auto get(const U& x)
-> decltype(Trait::get(x, make_sum_type_token<Trait, T>())) {
-> decltype(Trait::get(x, make_sum_type_token<Trait, T>())) {
return Trait::get(x, make_sum_type_token<Trait, T>());
}
......@@ -68,7 +67,7 @@ auto get(const U& x)
/// `nullptr` otherwise.
template <class T, class U, class Trait = sum_type_access<U>>
auto get_if(U* x)
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
return Trait::get_if(x, make_sum_type_token<Trait, T>());
}
......@@ -76,7 +75,7 @@ auto get_if(U* x)
/// `nullptr` otherwise.
template <class T, class U, class Trait = sum_type_access<U>>
auto get_if(const U* x)
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
-> decltype(Trait::get_if(x, make_sum_type_token<Trait, T>())) {
return Trait::get_if(x, make_sum_type_token<Trait, T>());
}
......@@ -99,8 +98,8 @@ struct sum_type_visit_result_impl<false, F, Ts...> {};
template <class F, class... Ts>
struct sum_type_visit_result
: sum_type_visit_result_impl<
detail::conjunction<SumType<Ts>()...>::value, F, Ts...> {};
: sum_type_visit_result_impl<detail::conjunction<SumType<Ts>()...>::value, F,
Ts...> {};
template <class F, class... Ts>
using sum_type_visit_result_t =
......@@ -129,7 +128,6 @@ struct visit_impl<Result, 0> {
}
};
template <class Result, size_t I, class Visitor>
struct visit_impl_continuation {
Visitor& f;
......
......@@ -5,12 +5,12 @@
#pragma once
#include <ctime>
#include <string_view>
#include <unordered_map>
#include <vector>
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
#include "caf/telemetry/counter.hpp"
#include "caf/telemetry/gauge.hpp"
#include "caf/telemetry/histogram.hpp"
......@@ -51,7 +51,7 @@ public:
/// Returns a string view into the internal buffer.
/// @warning This view may become invalid when calling any non-const member
/// function on the collector object.
[[nodiscard]] string_view str() const noexcept {
[[nodiscard]] std::string_view str() const noexcept {
return {buf_.data(), buf_.size()};
}
......@@ -100,8 +100,8 @@ public:
/// @param registry Source for the metrics.
/// @param now Current system time.
/// @returns a view into the filled buffer.
string_view collect_from(const metric_registry& registry,
timestamp now = make_timestamp());
std::string_view collect_from(const metric_registry& registry,
timestamp now = make_timestamp());
// -- call operators for the metric registry ---------------------------------
......@@ -141,13 +141,15 @@ private:
/// Sets `current_family_` if not pointing to `family` already. When setting
/// the member variable, also writes meta information to `buf_`.
void set_current_family(const metric_family* family,
string_view prometheus_type);
std::string_view prometheus_type);
void append_impl(const metric_family* family, string_view prometheus_type,
const metric* instance, int64_t value);
void append_impl(const metric_family* family,
std::string_view prometheus_type, const metric* instance,
int64_t value);
void append_impl(const metric_family* family, string_view prometheus_type,
const metric* instance, double value);
void append_impl(const metric_family* family,
std::string_view prometheus_type, const metric* instance,
double value);
template <class BucketType, class ValueType>
void append_histogram_impl(const metric_family* family,
......
......@@ -5,12 +5,12 @@
#pragma once
#include <string>
#include <string_view>
#include "caf/detail/comparable.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
#include "caf/hash/fnv.hpp"
#include "caf/string_view.hpp"
namespace caf::telemetry {
......@@ -30,22 +30,21 @@ public:
label& operator=(const label&) = default;
/// @pre `name` matches the regex `[a-zA-Z_:][a-zA-Z0-9_:]*`
label(string_view name, string_view value);
label(std::string_view name, std::string_view value);
explicit label(const label_view& view);
// -- properties -------------------------------------------------------------
string_view name() const noexcept {
return string_view{str_.data(), name_length_};
std::string_view name() const noexcept {
return {str_.data(), name_length_};
}
string_view value() const noexcept {
return string_view{str_.data() + name_length_ + 1,
str_.size() - name_length_ - 1};
std::string_view value() const noexcept {
return {str_.data() + name_length_ + 1, str_.size() - name_length_ - 1};
}
void value(string_view new_value);
void value(std::string_view new_value);
/// Returns the label in `name=value` notation.
const std::string& str() const noexcept {
......
......@@ -4,11 +4,12 @@
#pragma once
#include <string_view>
#include "caf/detail/comparable.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/fwd.hpp"
#include "caf/hash/fnv.hpp"
#include "caf/string_view.hpp"
namespace caf::telemetry {
......@@ -24,17 +25,18 @@ public:
label_view& operator=(const label_view&) = default;
/// @pre `key` matches the regex `[a-zA-Z_:][a-zA-Z0-9_:]*`
label_view(string_view name, string_view value) : name_(name), value_(value) {
label_view(std::string_view name, std::string_view value)
: name_(name), value_(value) {
// nop
}
// -- properties -------------------------------------------------------------
string_view name() const noexcept {
std::string_view name() const noexcept {
return name_;
}
string_view value() const noexcept {
std::string_view value() const noexcept {
return value_;
}
......@@ -45,8 +47,8 @@ public:
int compare(const label_view& x) const noexcept;
private:
string_view name_;
string_view value_;
std::string_view name_;
std::string_view value_;
};
/// Returns the @ref label_view in `name=value` notation.
......
......@@ -9,7 +9,6 @@
#include <vector>
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
#include "caf/telemetry/label.hpp"
namespace caf::telemetry {
......
......@@ -10,7 +10,6 @@
#include <mutex>
#include "caf/span.hpp"
#include "caf/string_view.hpp"
#include "caf/telemetry/label.hpp"
#include "caf/telemetry/label_view.hpp"
#include "caf/telemetry/metric.hpp"
......
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#pragma once
#include <cstdint>
#include <functional>
#include <typeinfo>
#include "caf/detail/core_export.hpp"
#include "caf/error_code.hpp"
#include "caf/fwd.hpp"
#include "caf/rtti_pair.hpp"
#include "caf/type_nr.hpp"
namespace caf {
/// Represents a single type-erased value.
class CAF_CORE_EXPORT type_erased_value {
public:
// -- constructors, destructors, and assignment operators --------------------
virtual ~type_erased_value();
// -- pure virtual modifiers -------------------------------------------------
/// Returns a mutable pointer to the stored value.
virtual void* get_mutable() = 0;
/// Load the content for the stored value from `source`.
virtual error load(deserializer& source) = 0;
/// Load the content for the stored value from `source`.
virtual error_code<sec> load(binary_deserializer& source) = 0;
// -- pure virtual observers -------------------------------------------------
/// Returns the type number and type information object for the stored value.
virtual rtti_pair type() const = 0;
/// Returns a pointer to the stored value.
virtual const void* get() const = 0;
/// Saves the content of the stored value to `sink`.
virtual error save(serializer& sink) const = 0;
/// Saves the content of the stored value to `sink`.
virtual error_code<sec> save(binary_serializer& sink) const = 0;
/// Converts the stored value to a string.
virtual std::string stringify() const = 0;
/// Returns a copy of the stored value.
virtual type_erased_value_ptr copy() const = 0;
// -- observers --------------------------------------------------------------
/// Checks whether the type of the stored value matches
/// the type nr and type info object.
bool matches(uint16_t nr, const std::type_info* ptr) const;
// -- convenience functions --------------------------------------------------
/// Returns the type number for the stored value.
uint16_t type_nr() const {
return type().first;
}
/// Checks whether the type of the stored value matches `rtti`.
bool matches(const rtti_pair& rtti) const {
return matches(rtti.first, rtti.second);
}
/// Convenience function for `reinterpret_cast<const T*>(get())`.
template <class T>
const T& get_as() const {
return *reinterpret_cast<const T*>(get());
}
/// Convenience function for `reinterpret_cast<T*>(get_mutable())`.
template <class T>
T& get_mutable_as() {
return *reinterpret_cast<T*>(get_mutable());
}
};
/// @relates type_erased_value
CAF_CORE_EXPORT error inspect(serializer& f, const type_erased_value& x);
/// @relates type_erased_value
CAF_CORE_EXPORT error inspect(deserializer& f, type_erased_value& x);
/// @relates type_erased_value
inline auto inspect(binary_serializer& f, const type_erased_value& x) {
return x.save(f);
}
/// @relates type_erased_value
inline auto inspect(binary_deserializer& f, type_erased_value& x) {
return x.load(f);
}
/// @relates type_erased_value
inline auto to_string(const type_erased_value& x) {
return x.stringify();
}
} // namespace caf
......@@ -7,6 +7,7 @@
#include <cstdint>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include "caf/detail/core_export.hpp"
......@@ -14,7 +15,6 @@
#include "caf/detail/pp.hpp"
#include "caf/detail/squashed_int.hpp"
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
#include "caf/timespan.hpp"
#include "caf/timestamp.hpp"
......@@ -53,7 +53,7 @@ struct type_name_by_id;
/// Convenience alias for `type_name_by_id<I>::value`.
/// @relates type_name_by_id
template <type_id_t I>
constexpr string_view type_name_by_id_v = type_name_by_id<I>::value;
constexpr std::string_view type_name_by_id_v = type_name_by_id<I>::value;
/// Convenience type that resolves to `type_name_by_id<type_id_v<T>>`.
template <class T>
......@@ -63,13 +63,13 @@ struct type_name;
/// manually.
template <>
struct type_name<void> {
static constexpr string_view value = "void";
static constexpr std::string_view value = "void";
};
/// Convenience alias for `type_name<T>::value`.
/// @relates type_name
template <class T>
constexpr string_view type_name_v = type_name<T>::value;
constexpr std::string_view type_name_v = type_name<T>::value;
/// The first type ID not reserved by CAF and its modules.
constexpr type_id_t first_custom_type_id = 200;
......@@ -80,7 +80,7 @@ constexpr bool has_type_id_v = detail::is_complete<type_id<T>>;
/// Returns `type_name_v<T>` if available, "anonymous" otherwise.
template <class T>
string_view type_name_or_anonymous() {
std::string_view type_name_or_anonymous() {
if constexpr (detail::is_complete<type_name<T>>)
return type_name<T>::value;
else
......@@ -98,10 +98,10 @@ type_id_t type_id_or_invalid() {
/// Returns the type name of given `type` or an empty string if `type` is an
/// invalid ID.
CAF_CORE_EXPORT string_view query_type_name(type_id_t type);
CAF_CORE_EXPORT std::string_view query_type_name(type_id_t type);
/// Returns the type of given `name` or `invalid_type_id` if no type matches.
CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
CAF_CORE_EXPORT type_id_t query_type_id(std::string_view name);
} // namespace caf
......@@ -153,7 +153,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
}; \
template <> \
struct type_name<::CAF_PP_EXPAND fully_qualified_name> { \
static constexpr string_view value \
static constexpr std::string_view value \
= CAF_PP_STR(CAF_PP_EXPAND fully_qualified_name); \
}; \
template <> \
......@@ -170,7 +170,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
}; \
template <> \
struct type_name<::CAF_PP_EXPAND fully_qualified_name> { \
static constexpr string_view value = user_type_name; \
static constexpr std::string_view value = user_type_name; \
}; \
template <> \
struct type_name_by_id<type_id<::CAF_PP_EXPAND fully_qualified_name>::value> \
......@@ -223,7 +223,8 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
}; \
template <> \
struct type_name<CAF_PP_EXPAND type_expr> { \
static constexpr string_view value = CAF_PP_STR(CAF_PP_EXPAND type_expr); \
static constexpr std::string_view value \
= CAF_PP_STR(CAF_PP_EXPAND type_expr); \
}; \
template <> \
struct type_name_by_id<type_id<CAF_PP_EXPAND type_expr>::value> \
......@@ -239,7 +240,7 @@ CAF_CORE_EXPORT type_id_t query_type_id(string_view name);
}; \
template <> \
struct type_name<CAF_PP_EXPAND type_expr> { \
static constexpr string_view value = user_type_name; \
static constexpr std::string_view value = user_type_name; \
}; \
template <> \
struct type_name_by_id<type_id<CAF_PP_EXPAND type_expr>::value> \
......
......@@ -5,6 +5,7 @@
#pragma once
#include <cstdint>
#include <string_view>
#include <vector>
#include "caf/detail/comparable.hpp"
......@@ -17,14 +18,13 @@
#include "caf/intrusive_ptr.hpp"
#include "caf/ip_address.hpp"
#include "caf/make_counted.hpp"
#include "caf/string_view.hpp"
#include "caf/variant.hpp"
namespace caf {
/// A URI according to RFC 3986.
class CAF_CORE_EXPORT uri : detail::comparable<uri>,
detail::comparable<uri, string_view> {
detail::comparable<uri, std::string_view> {
public:
// -- friends ----------------------------------------------------------------
......@@ -57,7 +57,7 @@ public:
};
/// Separates the query component into key-value pairs.
using path_list = std::vector<string_view>;
using path_list = std::vector<std::string_view>;
/// Separates the query component into key-value pairs.
using query_map = detail::unordered_flat_map<std::string, std::string>;
......@@ -154,12 +154,12 @@ public:
}
/// Returns the full URI as provided by the user.
string_view str() const noexcept {
std::string_view str() const noexcept {
return impl_->str;
}
/// Returns the scheme component.
string_view scheme() const noexcept {
std::string_view scheme() const noexcept {
return impl_->scheme;
}
......@@ -169,7 +169,7 @@ public:
}
/// Returns the path component as provided by the user.
string_view path() const noexcept {
std::string_view path() const noexcept {
return impl_->path;
}
......@@ -179,7 +179,7 @@ public:
}
/// Returns the fragment component.
string_view fragment() const noexcept {
std::string_view fragment() const noexcept {
return impl_->fragment;
}
......@@ -189,7 +189,7 @@ public:
/// Returns a new URI with the `authority` component only.
/// @returns A new URI in the form `scheme://authority` if the authority
/// exists, otherwise `none`.`
optional<uri> authority_only() const;
std::optional<uri> authority_only() const;
// -- comparison -------------------------------------------------------------
......@@ -197,18 +197,19 @@ public:
return str().compare(other.str());
}
auto compare(string_view x) const noexcept {
auto compare(std::string_view x) const noexcept {
return str().compare(x);
}
// -- parsing ----------------------------------------------------------------
/// Returns whether `parse` would produce a valid URI.
static bool can_parse(string_view str) noexcept;
static bool can_parse(std::string_view str) noexcept;
// -- URI encoding, AKA Percent encoding -------------------------------------
static void encode(std::string& str, string_view x, bool is_path = false);
static void encode(std::string& str, std::string_view x,
bool is_path = false);
static void decode(std::string& str);
......@@ -244,10 +245,10 @@ CAF_CORE_EXPORT std::string to_string(const uri& x);
CAF_CORE_EXPORT std::string to_string(const uri::authority_type& x);
/// @relates uri
CAF_CORE_EXPORT error parse(string_view str, uri& dest);
CAF_CORE_EXPORT error parse(std::string_view str, uri& dest);
/// @relates uri
CAF_CORE_EXPORT expected<uri> make_uri(string_view str);
CAF_CORE_EXPORT expected<uri> make_uri(std::string_view str);
template <>
struct inspector_access<uri> : inspector_access_base<uri> {
......
......@@ -5,16 +5,16 @@
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <string>
#include <string_view>
#include "caf/byte.hpp"
#include "caf/detail/comparable.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/error.hpp"
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
namespace caf {
......@@ -23,7 +23,7 @@ namespace caf {
/// can read all UUID versions, it can only create random-generated ones.
class CAF_CORE_EXPORT uuid : detail::comparable<uuid> {
public:
using array_type = std::array<byte, 16>;
using array_type = std::array<std::byte, 16>;
/// Creates the nil UUID with all 128 bits set to zero.
uuid() noexcept;
......@@ -122,7 +122,7 @@ public:
}
/// Returns whether `parse` would produce a valid UUID.
static bool can_parse(string_view str) noexcept;
static bool can_parse(std::string_view str) noexcept;
/// Lexicographically compares `this` and `other`.
/// @returns a negative value if `*this < other`, zero if `*this == other`
......@@ -151,13 +151,13 @@ private:
};
/// @relates uuid
CAF_CORE_EXPORT error parse(string_view str, uuid& dest);
CAF_CORE_EXPORT error parse(std::string_view str, uuid& dest);
/// @relates uuid
CAF_CORE_EXPORT std::string to_string(const uuid& x);
/// @relates uuid
CAF_CORE_EXPORT expected<uuid> make_uuid(string_view str);
CAF_CORE_EXPORT expected<uuid> make_uuid(std::string_view str);
/// @relates uuid
template <class Inspector>
......
This diff is collapsed.
......@@ -235,9 +235,10 @@ auto make_actor_metric_families(telemetry::metric_registry& reg) {
5., // 5s
}};
return actor_system::actor_metric_families_t{
reg.histogram_family<double>(
"caf.actor", "processing-time", {"name"}, default_buckets,
"Time an actor needs to process messages.", "seconds"),
reg.histogram_family<double>("caf.actor", "processing-time", {"name"},
default_buckets,
"Time an actor needs to process messages.",
"seconds"),
reg.histogram_family<double>(
"caf.actor", "mailbox-time", {"name"}, default_buckets,
"Time a message waits in the mailbox before processing.", "seconds"),
......@@ -511,7 +512,7 @@ void actor_system::thread_terminates() {
expected<strong_actor_ptr>
actor_system::dyn_spawn_impl(const std::string& name, message& args,
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_ARG(expected_ifs));
if (name.empty())
......
......@@ -129,7 +129,7 @@ settings actor_system_config::dump_content() const {
put_missing(console_group, "excluded-components", std::vector<std::string>{});
// -- middleman parameters
auto& middleman_group = caf_group["middleman"].as_dictionary();
auto default_id = to_string(defaults::middleman::app_identifier);
auto default_id = std::string{defaults::middleman::app_identifier};
put_missing(middleman_group, "app-identifiers",
std::vector<std::string>{std::move(default_id)});
put_missing(middleman_group, "enable-automatic-connections", false);
......@@ -339,7 +339,7 @@ actor_system_config& actor_system_config::add_actor_factory(std::string name,
return *this;
}
actor_system_config& actor_system_config::set_impl(string_view name,
actor_system_config& actor_system_config::set_impl(std::string_view name,
config_value value) {
auto opt = custom_options_.qualified_name_lookup(name);
if (opt == nullptr) {
......@@ -405,7 +405,7 @@ actor_system_config::extract_config_file_path(string_list& args) {
auto ptr = custom_options_.qualified_name_lookup("global.config-file");
CAF_ASSERT(ptr != nullptr);
string_list::iterator i;
string_view path;
std::string_view path;
std::tie(i, path) = find_by_long_name(*ptr, args.begin(), args.end());
if (i == args.end()) {
return {none, std::string{}};
......
......@@ -84,12 +84,13 @@ void binary_deserializer::skip(size_t num_bytes) {
current_ += num_bytes;
}
void binary_deserializer::reset(span<const byte> bytes) noexcept {
void binary_deserializer::reset(span<const std::byte> bytes) noexcept {
current_ = bytes.data();
end_ = current_ + bytes.size();
}
bool binary_deserializer::begin_field(string_view, bool& is_present) noexcept {
bool binary_deserializer::begin_field(std::string_view,
bool& is_present) noexcept {
auto tmp = uint8_t{0};
if (!value(tmp))
return false;
......@@ -104,7 +105,8 @@ constexpr size_t max_value = static_cast<size_t>(std::numeric_limits<T>::max());
} // namespace
bool binary_deserializer::begin_field(string_view, span<const type_id_t> types,
bool binary_deserializer::begin_field(std::string_view,
span<const type_id_t> types,
size_t& index) noexcept {
auto f = [&](auto tmp) {
if (!value(tmp))
......@@ -128,7 +130,7 @@ bool binary_deserializer::begin_field(string_view, span<const type_id_t> types,
}
}
bool binary_deserializer::begin_field(string_view, bool& is_present,
bool binary_deserializer::begin_field(std::string_view, bool& is_present,
span<const type_id_t> types,
size_t& index) noexcept {
auto f = [&](auto tmp) {
......@@ -166,7 +168,7 @@ bool binary_deserializer::value(bool& x) noexcept {
return true;
}
bool binary_deserializer::value(byte& x) noexcept {
bool binary_deserializer::value(std::byte& x) noexcept {
if (range_check(1)) {
x = *current_++;
return true;
......@@ -240,7 +242,7 @@ bool binary_deserializer::value(long double& x) {
return false;
}
bool binary_deserializer::value(span<byte> x) noexcept {
bool binary_deserializer::value(span<std::byte> x) noexcept {
if (!range_check(x.size())) {
emplace_error(sec::end_of_stream);
return false;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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