Commit 83db896d authored by Dominik Charousset's avatar Dominik Charousset

Silence deprecation warnings for std::byte

parent 1b29bf10
......@@ -26,6 +26,7 @@ is based on [Keep a Changelog](https://keepachangelog.com).
- Passing a function reference to the constructor of an actor caused a compiler
error when building with logging enabled. CAF now properly handles this edge
case and logs such constructor arguments as `<unprintable>` (#1229).
- Silence a deprecated-enum-conversion warning for `std::byte` (#1230).
## [0.18.0] - 2021-01-25
......
......@@ -5,6 +5,7 @@
#pragma once
#include <chrono>
#include <cstddef>
#include <memory>
#include <tuple>
#include <utility>
......@@ -475,6 +476,23 @@ struct inspector_access<std::unique_ptr<error::data>>
// nop
};
// -- inspection support for std::byte -----------------------------------------
#ifdef __cpp_lib_byte
template <>
struct inspector_access<std::byte> : inspector_access_base<std::byte> {
template <class Inspector>
[[nodiscard]] static bool apply(Inspector& f, std::byte& x) {
using integer_type = std::underlying_type_t<std::byte>;
auto get = [&x] { return static_cast<integer_type>(x); };
auto set = [&x](integer_type val) { x = static_cast<std::byte>(val); };
return f.apply(get, set);
}
};
#endif
// -- inspection support for variant<Ts...> ------------------------------------
template <class T>
......
......@@ -10,8 +10,7 @@
namespace caf {
/// Provides default implementations for `save_field`, `load_field`, and
/// `apply_value`.
/// Provides default implementations for `save_field` and `load_field`.
template <class T>
struct inspector_access_base {
/// Loads a mandatory field from `f`.
......
......@@ -746,4 +746,33 @@ end object)_";
}
}
#ifdef __cpp_lib_byte
SCENARIO("load inspectors support std::byte") {
GIVEN("a struct with std::byte") {
struct byte_test {
std::byte v1 = std::byte{0};
optional<std::byte> v2;
};
auto x = byte_test{};
WHEN("inspecting the struct") {
THEN("CAF treats std::byte like an unsigned integer") {
CHECK(f.object(x).fields(f.field("v1", x.v1), f.field("v2", x.v2)));
CHECK(!f.get_error());
std::string baseline = R"_(
begin object anonymous
begin field v1
uint8_t value
end field
begin optional field v2
end field
end object)_";
CHECK_EQ(f.log, baseline);
}
}
}
}
#endif
CAF_TEST_FIXTURE_SCOPE_END()
......@@ -783,4 +783,34 @@ end object)_");
}
}
#ifdef __cpp_lib_byte
SCENARIO("save inspectors support std::byte") {
GIVEN("a struct with std::byte") {
struct byte_test {
std::byte v1;
optional<std::byte> v2;
};
auto x = byte_test{std::byte{1}, std::byte{2}};
WHEN("inspecting the struct") {
THEN("CAF treats std::byte like an unsigned integer") {
CHECK(f.object(x).fields(f.field("v1", x.v1), f.field("v2", x.v2)));
CHECK(!f.get_error());
std::string baseline = R"_(
begin object anonymous
begin field v1
uint8_t value
end field
begin optional field v2
uint8_t value
end field
end object)_";
CHECK_EQ(f.log, baseline);
}
}
}
}
#endif
CAF_TEST_FIXTURE_SCOPE_END()
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