Commit 17a85cab authored by Dominik Charousset's avatar Dominik Charousset

Use if constexpr where appropriate

parent d5b15662
......@@ -52,7 +52,7 @@ namespace caf {
/// type is not implemented as a simple variant alias because variants cannot
/// contain lists of themselves.
class CAF_CORE_EXPORT config_value {
public:
public:
// -- member types -----------------------------------------------------------
using integer = int64_t;
......@@ -149,7 +149,7 @@ public:
return &data_;
}
private:
private:
// -- properties -------------------------------------------------------------
static const char* type_name_at_index(size_t index) noexcept;
......@@ -305,7 +305,7 @@ struct CAF_CORE_EXPORT config_value_access<std::string> {
template <bool IsNested>
static void parse_cli(string_parser_state& ps, std::string& x,
std::integral_constant<bool, IsNested>) {
if (IsNested)
if constexpr (IsNested)
detail::parse_element(ps, x, ",={}[]");
else
detail::parse(ps, x);
......
......@@ -52,25 +52,14 @@ config_value get_impl(const void* ptr) {
return config_value{trait::convert(*reinterpret_cast<const T*>(ptr))};
}
template <class T>
typename std::enable_if<detail::has_clear_member<T>::value>::type
clear_before_parsing(T& xs) {
xs.clear();
}
template <class T>
typename std::enable_if<!detail::has_clear_member<T>::value>::type
clear_before_parsing(T&) {
// nop
}
template <class T>
expected<config_value> parse_impl(T* ptr, string_view str) {
if (!ptr) {
T tmp;
return parse_impl(&tmp, str);
}
clear_before_parsing(*ptr);
if constexpr (detail::has_clear_member<T>::value)
ptr->clear();
using trait = select_config_value_access_t<T>;
string_parser_state ps{str.begin(), str.end()};
trait::parse_cli(ps, *ptr, top_level_cli_parsing);
......
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