1
0
Fork 0

Codechange: Allow ConvertibleThroughBase types to be used as settings. (#13466)

pull/13469/head
Peter Nelson 2025-02-04 19:06:37 +00:00 committed by GitHub
parent adc79aca09
commit 603630c1ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 18 deletions

View File

@ -21,4 +21,12 @@ concept ConvertibleThroughBase = requires(T const a) {
{ a.base() } noexcept -> std::convertible_to<int64_t>;
};
/**
* Type is convertible to TTo, either directly or through ConvertibleThroughBase.
* @tparam T The type under consideration.
* @tparam TTo The type to convert to.
*/
template <typename T, typename TTo>
concept ConvertibleThroughBaseOrTo = std::is_convertible_v<T, TTo> || ConvertibleThroughBase<T>;
#endif /* CONVERTIBLE_THROUGH_BASE_HPP */

View File

@ -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 <typename TBaseType, typename TTag, typename... TProperties>
struct EMPTY_BASES Typedef : public StrongTypedefBase, public TProperties::template mixin<Typedef<TBaseType, TTag, TProperties...>, TBaseType>... {
struct EMPTY_BASES Typedef : public TProperties::template mixin<Typedef<TBaseType, TTag, TProperties...>, TBaseType>... {
using BaseType = TBaseType;
constexpr Typedef() = default;

View File

@ -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::disjunction_v<std::is_convertible<Tdef, int32_t>, std::is_base_of<StrongTypedefBase, Tdef>>, int> = 0,
std::enable_if_t<std::disjunction_v<std::is_convertible<Tmin, int32_t>, std::is_base_of<StrongTypedefBase, Tmin>>, int> = 0,
std::enable_if_t<std::disjunction_v<std::is_convertible<Tmax, uint32_t>, std::is_base_of<StrongTypedefBase, Tmax>>, int> = 0,
std::enable_if_t<std::disjunction_v<std::is_convertible<Tinterval, int32_t>, std::is_base_of<StrongTypedefBase, Tinterval>>, int> = 0
>
template <ConvertibleThroughBaseOrTo<int32_t> Tdef, ConvertibleThroughBaseOrTo<int32_t> Tmin, ConvertibleThroughBaseOrTo<uint32_t> Tmax, ConvertibleThroughBaseOrTo<int32_t> 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<StrongTypedefBase, Tdef>) {
if constexpr (ConvertibleThroughBase<Tdef>) {
this->def = def.base();
} else {
this->def = def;
}
if constexpr (std::is_base_of_v<StrongTypedefBase, Tmin>) {
if constexpr (ConvertibleThroughBase<Tmin>) {
this->min = min.base();
} else {
this->min = min;
}
if constexpr (std::is_base_of_v<StrongTypedefBase, Tmax>) {
if constexpr (ConvertibleThroughBase<Tmax>) {
this->max = max.base();
} else {
this->max = max;
}
if constexpr (std::is_base_of_v<StrongTypedefBase, Tinterval>) {
if constexpr (ConvertibleThroughBase<Tinterval>) {
this->interval = interval.base();
} else {
this->interval = interval;