Commit edcd27cb authored by Dominik Charousset's avatar Dominik Charousset

Fix get_or with non-default template parameter

parent 5071ccb3
......@@ -540,11 +540,10 @@ auto get_or(const config_value& x, Fallback&& fallback) {
else
return guide::convert(std::forward<Fallback>(fallback));
} else {
using value_type = std::decay_t<Fallback>;
if (auto val = get_as<value_type>(x))
if (auto val = get_as<To>(x))
return std::move(*val);
else
return std::forward<Fallback>(fallback);
return To{std::forward<Fallback>(fallback)};
}
}
......
......@@ -585,7 +585,7 @@ SCENARIO("get_as can convert config values to custom types") {
SCENARIO("get_or converts or returns a fallback value") {
using namespace caf::literals;
GIVEN("the config value 42") {
config_value x{42};
auto x = config_value{42};
WHEN("using get_or with type int") {
THEN("CAF ignores the default value") {
CHECK_EQ(get_or(x, 10), 42);
......@@ -610,6 +610,21 @@ SCENARIO("get_or converts or returns a fallback value") {
CHECK_EQ(result, std::vector<int>({10, 20, 30}));
}
}
WHEN("using get_or with type i64_wrapper") {
THEN("CAF returns i64_wrapper{42}") {
auto result = get_or<i64_wrapper>(x, 10);
CHECK_EQ(result.value, 42);
}
}
}
GIVEN("the config value 'hello world'") {
auto x = config_value{"hello world"};
WHEN("using get_or with type i64_wrapper") {
THEN("CAF returns the fallback value") {
auto result = get_or<i64_wrapper>(x, 10);
CHECK_EQ(result.value, 10);
}
}
}
}
......
......@@ -83,7 +83,7 @@ struct i32_wrapper {
template <class Inspector>
friend bool inspect(Inspector& f, i32_wrapper& x) {
return f.object(x).fields(f.field("value", x.value));
return f.apply(x.value);
}
};
......@@ -97,13 +97,17 @@ struct i64_wrapper {
++instances;
}
explicit i64_wrapper(int64_t val) : value(val) {
++instances;
}
~i64_wrapper() {
--instances;
}
template <class Inspector>
friend bool inspect(Inspector& f, i64_wrapper& x) {
return f.object(x).fields(f.field("value", x.value));
return f.apply(x.value);
}
};
......
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