Unverified Commit 3b0d4639 authored by Noir's avatar Noir Committed by GitHub

Merge pull request #1237

Silence deprecation warnings for std::byte
parents f87938a3 7004d332
...@@ -30,6 +30,7 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -30,6 +30,7 @@ is based on [Keep a Changelog](https://keepachangelog.com).
`--caf.metrics-filters.actors.includes=...` to a CAF application resulted in `--caf.metrics-filters.actors.includes=...` to a CAF application resulted in
an error. The `includes` and `excludes` filters are now consistently handled an error. The `includes` and `excludes` filters are now consistently handled
and accepted in config files as well as on the command line (#1238). and accepted in config files as well as on the command line (#1238).
- Silence a deprecated-enum-conversion warning for `std::byte` (#1230).
## [0.18.0] - 2021-01-25 ## [0.18.0] - 2021-01-25
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#pragma once #pragma once
#include <chrono> #include <chrono>
#include <cstddef>
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include <utility> #include <utility>
...@@ -475,6 +476,23 @@ struct inspector_access<std::unique_ptr<error::data>> ...@@ -475,6 +476,23 @@ struct inspector_access<std::unique_ptr<error::data>>
// nop // 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...> ------------------------------------ // -- inspection support for variant<Ts...> ------------------------------------
template <class T> template <class T>
......
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
namespace caf { namespace caf {
/// Provides default implementations for `save_field`, `load_field`, and /// Provides default implementations for `save_field` and `load_field`.
/// `apply_value`.
template <class T> template <class T>
struct inspector_access_base { struct inspector_access_base {
/// Loads a mandatory field from `f`. /// Loads a mandatory field from `f`.
......
...@@ -746,4 +746,33 @@ end object)_"; ...@@ -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() CAF_TEST_FIXTURE_SCOPE_END()
...@@ -783,4 +783,34 @@ end object)_"); ...@@ -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() 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