Config: Fix template deduction for implicit conversions

This excludes the second argument from template deduction.

Otherwise, it is required to manually cast the second argument to
the ConfigInfo type (because implicit conversions won't work).

e.g. to set the value for a ConfigInfo<std::string> from a string
literal, you'd need a ugly `std::string("yourstring")`.
This commit is contained in:
Léo Lam
2018-05-11 20:34:39 +02:00
parent f0c5b76186
commit 7dca7c237e
8 changed files with 23 additions and 20 deletions

View File

@ -70,26 +70,26 @@ LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
}
template <typename T>
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
void Set(LayerType layer, const ConfigInfo<T>& info, const std::common_type_t<T>& value)
{
GetLayer(layer)->Set(info, value);
InvokeConfigChangedCallbacks();
}
template <typename T>
void SetBase(const ConfigInfo<T>& info, const T& value)
void SetBase(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
{
Set<T>(LayerType::Base, info, value);
}
template <typename T>
void SetCurrent(const ConfigInfo<T>& info, const T& value)
void SetCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
{
Set<T>(LayerType::CurrentRun, info, value);
}
template <typename T>
void SetBaseOrCurrent(const ConfigInfo<T>& info, const T& value)
void SetBaseOrCurrent(const ConfigInfo<T>& info, const std::common_type_t<T>& value)
{
if (GetActiveLayerForConfig(info) == LayerType::Base)
Set<T>(LayerType::Base, info, value);