feat: swap the default value with min/max value in binstore serde.
considering setting default value is common that min/max value, move default value template argument ahead of min/max template argument, because C++ can not skip template argument like Rust `_` does.
This commit is contained in:
@ -46,9 +46,9 @@ namespace yycc::carton::binstore::serdes {
|
||||
using SerDesValueType = T::ValueType;
|
||||
|
||||
template<std::integral T,
|
||||
auto TDefault = static_cast<T>(0),
|
||||
auto TMin = std::numeric_limits<T>::min(),
|
||||
auto TMax = std::numeric_limits<T>::max(),
|
||||
auto TDefault = static_cast<T>(0)>
|
||||
auto TMax = std::numeric_limits<T>::max()>
|
||||
struct IntegralSerDes {
|
||||
IntegralSerDes() = default;
|
||||
YYCC_DEFAULT_COPY_MOVE(IntegralSerDes)
|
||||
@ -81,9 +81,9 @@ namespace yycc::carton::binstore::serdes {
|
||||
};
|
||||
|
||||
template<std::floating_point T,
|
||||
auto TDefault = static_cast<T>(0),
|
||||
auto TMin = std::numeric_limits<T>::lowest(),
|
||||
auto TMax = std::numeric_limits<T>::max(),
|
||||
auto TDefault = static_cast<T>(0)>
|
||||
auto TMax = std::numeric_limits<T>::max()>
|
||||
struct FloatingPointSerDes {
|
||||
FloatingPointSerDes() {
|
||||
// TODO: Remove this and make it "= default" when 3 common STL make std::isfinite become constexpr.
|
||||
@ -122,7 +122,7 @@ namespace yycc::carton::binstore::serdes {
|
||||
NS_YYCC_BINSTORE_TYPES::ByteArray reset() const { return this->serialize(TDefault).value(); }
|
||||
};
|
||||
|
||||
template<typename T, auto TDefault = static_cast<T>(0)>
|
||||
template<typename T, T TDefault>
|
||||
requires std::is_enum_v<T>
|
||||
struct EnumSerDes {
|
||||
EnumSerDes() = default;
|
||||
@ -142,11 +142,7 @@ namespace yycc::carton::binstore::serdes {
|
||||
NS_YYCC_BINSTORE_TYPES::ByteArray reset() const { return inner.reset(); }
|
||||
|
||||
private:
|
||||
IntegralSerDes<UnderlyingType,
|
||||
std::numeric_limits<UnderlyingType>::min(),
|
||||
std::numeric_limits<UnderlyingType>::max(),
|
||||
static_cast<UnderlyingType>(TDefault)>
|
||||
inner;
|
||||
IntegralSerDes<UnderlyingType, static_cast<UnderlyingType>(TDefault)> inner;
|
||||
};
|
||||
|
||||
template<bool TDefault = false>
|
||||
|
||||
@ -78,9 +78,9 @@ namespace yycctest::carton::binstore {
|
||||
Token string_setting;
|
||||
using StringSettingSerDes = serdes::StringSerDes;
|
||||
Token bool_setting;
|
||||
using BoolSettingSerDes = serdes::BoolSerDes<>;
|
||||
using BoolSettingSerDes = serdes::BoolSerDes<false>;
|
||||
Token clamped_float_setting;
|
||||
using ClampedFloatSettingSerDes = serdes::FloatingPointSerDes<float, -1.0f, 1.0f>;
|
||||
using ClampedFloatSettingSerDes = serdes::FloatingPointSerDes<float, 0.0f, -1.0f, 1.0f>;
|
||||
Token enum_setting;
|
||||
using EnumSettingSerDes = serdes::EnumSerDes<TestEnum, TestEnum::Test1>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user