Skip to content

Commit

Permalink
Use std::enable_if_t in ConfigObject
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 1, 2023
1 parent ea0514b commit 7fa2263
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/preferences/configobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,9 @@ template <class ValueType> class ConfigObject {

// Sets the value for key to ValueType(value), over-writing pre-existing
// values. ResultType is serialized to string on a per-type basis.
template <class ResultType>
template<class ResultType, std::enable_if_t<!std::is_enum_v<ResultType>, bool> = true>
void setValue(const ConfigKey& key, const ResultType& value);
template<class EnumType>
requires std::is_enum_v<EnumType>
template<typename EnumType, std::enable_if_t<std::is_enum_v<EnumType>, bool> = true>
// we need to take value as const ref otherwise the overload is ambiguous
void setValue(const ConfigKey& key, const EnumType& value) {
setValue<int>(key, static_cast<int>(value));
Expand All @@ -175,11 +174,10 @@ template <class ValueType> class ConfigObject {

// Returns the value for key, converted to ResultType. If key is not present
// or the value cannot be converted to ResultType, returns default_value.
template <class ResultType>
template<class ResultType, std::enable_if_t<!std::is_enum_v<ResultType>, bool> = true>
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
QString getValue(const ConfigKey& key, const char* default_value) const;
template<typename EnumType>
requires std::is_enum_v<EnumType>
template<typename EnumType, std::enable_if_t<std::is_enum_v<EnumType>, bool> = true>
EnumType getValue(const ConfigKey& key, const EnumType& default_value) const {
// we need to take default_value as const ref otherwise the overload is ambiguous
return static_cast<EnumType>(getValue<int>(key, static_cast<int>(default_value)));
Expand Down

0 comments on commit 7fa2263

Please sign in to comment.