diff --git a/src/core/convertible_through_base.hpp b/src/core/convertible_through_base.hpp index 0b22f35cd5..6dc4a901be 100644 --- a/src/core/convertible_through_base.hpp +++ b/src/core/convertible_through_base.hpp @@ -21,4 +21,12 @@ concept ConvertibleThroughBase = requires(T const a) { { a.base() } noexcept -> std::convertible_to; }; +/** + * Type is convertible to TTo, either directly or through ConvertibleThroughBase. + * @tparam T The type under consideration. + * @tparam TTo The type to convert to. + */ +template +concept ConvertibleThroughBaseOrTo = std::is_convertible_v || ConvertibleThroughBase; + #endif /* CONVERTIBLE_THROUGH_BASE_HPP */ diff --git a/src/core/strong_typedef_type.hpp b/src/core/strong_typedef_type.hpp index fe5eda2127..f1b54223d0 100644 --- a/src/core/strong_typedef_type.hpp +++ b/src/core/strong_typedef_type.hpp @@ -12,9 +12,6 @@ #include "../3rdparty/fmt/format.h" -/** Non-templated base for #StrongType::Typedef for use with type trait queries. */ -struct StrongTypedefBase {}; - namespace StrongType { /** * Mix-in which makes the new Typedef comparable with itself and its base type. @@ -147,7 +144,7 @@ namespace StrongType { * @tparam TProperties A list of mixins to add to the class. */ template - struct EMPTY_BASES Typedef : public StrongTypedefBase, public TProperties::template mixin, TBaseType>... { + struct EMPTY_BASES Typedef : public TProperties::template mixin, TBaseType>... { using BaseType = TBaseType; constexpr Typedef() = default; diff --git a/src/settings_internal.h b/src/settings_internal.h index d1a8a71562..84231e9718 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -167,16 +167,7 @@ struct IntSettingDesc : SettingDesc { */ typedef void PostChangeCallback(int32_t value); - template < - typename Tdef, - typename Tmin, - typename Tmax, - typename Tinterval, - std::enable_if_t, std::is_base_of>, int> = 0, - std::enable_if_t, std::is_base_of>, int> = 0, - std::enable_if_t, std::is_base_of>, int> = 0, - std::enable_if_t, std::is_base_of>, int> = 0 - > + template Tdef, ConvertibleThroughBaseOrTo Tmin, ConvertibleThroughBaseOrTo Tmax, ConvertibleThroughBaseOrTo Tinterval> IntSettingDesc(const SaveLoad &save, SettingFlags flags, bool startup, Tdef def, Tmin min, Tmax max, Tinterval interval, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback, @@ -187,25 +178,25 @@ struct IntSettingDesc : SettingDesc { post_callback(post_callback), get_title_cb(get_title_cb), get_help_cb(get_help_cb), set_value_dparams_cb(set_value_dparams_cb), get_def_cb(get_def_cb), get_range_cb(get_range_cb) { - if constexpr (std::is_base_of_v) { + if constexpr (ConvertibleThroughBase) { this->def = def.base(); } else { this->def = def; } - if constexpr (std::is_base_of_v) { + if constexpr (ConvertibleThroughBase) { this->min = min.base(); } else { this->min = min; } - if constexpr (std::is_base_of_v) { + if constexpr (ConvertibleThroughBase) { this->max = max.base(); } else { this->max = max; } - if constexpr (std::is_base_of_v) { + if constexpr (ConvertibleThroughBase) { this->interval = interval.base(); } else { this->interval = interval;