Skip to content

Commit dcc6022

Browse files
committed
feat: simplify formatter's
1 parent 02a517e commit dcc6022

File tree

3 files changed

+21
-90
lines changed

3 files changed

+21
-90
lines changed

include/REX/REX/INI.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,13 @@ namespace REX::INI
8888
using Str = Setting<std::string, Store>;
8989
}
9090

91-
namespace REX::INI::Impl
91+
template <class T, class S, class CharT>
92+
struct std::formatter<REX::INI::Setting<T, S>, CharT> : std::formatter<T, CharT>
9293
{
93-
# ifdef __cpp_lib_format
94-
template <class T, class CharT>
95-
struct formatter : std::formatter<T, CharT>
94+
template <class FormatContext>
95+
auto format(const REX::INI::Setting<T, S>& a_setting, FormatContext& a_ctx) const
9696
{
97-
template <class FormatContext>
98-
auto format(REX::INI::Setting<T> a_setting, FormatContext& a_ctx) const
99-
{
100-
return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
101-
}
102-
};
103-
# endif
104-
}
105-
106-
# ifdef __cpp_lib_format
107-
namespace std
108-
{
109-
// clang-format off
110-
template <class CharT> struct formatter<REX::INI::Bool<>, CharT> : REX::INI::Impl::formatter<bool, CharT> {};
111-
template <class CharT> struct formatter<REX::INI::F32<>, CharT> : REX::INI::Impl::formatter<float, CharT> {};
112-
template <class CharT> struct formatter<REX::INI::F64<>, CharT> : REX::INI::Impl::formatter<double, CharT> {};
113-
template <class CharT> struct formatter<REX::INI::I8<>, CharT> : REX::INI::Impl::formatter<std::int8_t, CharT> {};
114-
template <class CharT> struct formatter<REX::INI::I16<>, CharT> : REX::INI::Impl::formatter<std::int16_t, CharT> {};
115-
template <class CharT> struct formatter<REX::INI::I32<>, CharT> : REX::INI::Impl::formatter<std::int32_t, CharT> {};
116-
template <class CharT> struct formatter<REX::INI::U8<>, CharT> : REX::INI::Impl::formatter<std::uint8_t, CharT> {};
117-
template <class CharT> struct formatter<REX::INI::U16<>, CharT> : REX::INI::Impl::formatter<std::uint16_t, CharT> {};
118-
template <class CharT> struct formatter<REX::INI::U32<>, CharT> : REX::INI::Impl::formatter<std::uint32_t, CharT> {};
119-
template <class CharT> struct formatter<REX::INI::Str<>, CharT> : REX::INI::Impl::formatter<std::string, CharT> {};
120-
// clang-format on
121-
}
122-
# endif
97+
return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
98+
}
99+
};
123100
#endif

include/REX/REX/JSON.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,13 @@ namespace REX::JSON
8585
using Str = Setting<std::string, Store>;
8686
}
8787

88-
namespace REX::JSON::Impl
88+
template <class T, class S, class CharT>
89+
struct std::formatter<REX::JSON::Setting<T, S>, CharT> : std::formatter<T, CharT>
8990
{
90-
# ifdef __cpp_lib_format
91-
template <class T, class CharT>
92-
struct formatter : std::formatter<T, CharT>
91+
template <class FormatContext>
92+
auto format(const REX::JSON::Setting<T, S>& a_setting, FormatContext& a_ctx) const
9393
{
94-
template <class FormatContext>
95-
auto format(REX::JSON::Setting<T> a_setting, FormatContext& a_ctx) const
96-
{
97-
return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
98-
}
99-
};
100-
# endif
101-
}
102-
103-
# ifdef __cpp_lib_format
104-
namespace std
105-
{
106-
// clang-format off
107-
template <class CharT> struct formatter<REX::JSON::Bool<>, CharT> : REX::JSON::Impl::formatter<bool, CharT> {};
108-
template <class CharT> struct formatter<REX::JSON::F32<>, CharT> : REX::JSON::Impl::formatter<float, CharT> {};
109-
template <class CharT> struct formatter<REX::JSON::F64<>, CharT> : REX::JSON::Impl::formatter<double, CharT> {};
110-
template <class CharT> struct formatter<REX::JSON::I8<>, CharT> : REX::JSON::Impl::formatter<std::int8_t, CharT> {};
111-
template <class CharT> struct formatter<REX::JSON::I16<>, CharT> : REX::JSON::Impl::formatter<std::int16_t, CharT> {};
112-
template <class CharT> struct formatter<REX::JSON::I32<>, CharT> : REX::JSON::Impl::formatter<std::int32_t, CharT> {};
113-
template <class CharT> struct formatter<REX::JSON::U8<>, CharT> : REX::JSON::Impl::formatter<std::uint8_t, CharT> {};
114-
template <class CharT> struct formatter<REX::JSON::U16<>, CharT> : REX::JSON::Impl::formatter<std::uint16_t, CharT> {};
115-
template <class CharT> struct formatter<REX::JSON::U32<>, CharT> : REX::JSON::Impl::formatter<std::uint32_t, CharT> {};
116-
template <class CharT> struct formatter<REX::JSON::Str<>, CharT> : REX::JSON::Impl::formatter<std::string, CharT> {};
117-
// clang-format on
118-
}
119-
# endif
94+
return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
95+
}
96+
};
12097
#endif

include/REX/REX/TOML.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,36 +104,13 @@ namespace REX::TOML
104104
using Str = Setting<std::string, Store>;
105105
}
106106

107-
namespace REX::TOML::Impl
107+
template <class T, class S, class CharT>
108+
struct std::formatter<REX::TOML::Setting<T, S>, CharT> : std::formatter<T, CharT>
108109
{
109-
# ifdef __cpp_lib_format
110-
template <class T, class CharT>
111-
struct formatter : std::formatter<T, CharT>
110+
template <class FormatContext>
111+
auto format(const REX::TOML::Setting<T, S>& a_setting, FormatContext& a_ctx) const
112112
{
113-
template <class FormatContext>
114-
auto format(REX::TOML::Setting<T> a_setting, FormatContext& a_ctx) const
115-
{
116-
return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
117-
}
118-
};
119-
# endif
120-
}
121-
122-
# ifdef __cpp_lib_format
123-
namespace std
124-
{
125-
// clang-format off
126-
template <class CharT> struct formatter<REX::TOML::Bool<>, CharT> : REX::TOML::Impl::formatter<bool, CharT> {};
127-
template <class CharT> struct formatter<REX::TOML::F32<>, CharT> : REX::TOML::Impl::formatter<float, CharT> {};
128-
template <class CharT> struct formatter<REX::TOML::F64<>, CharT> : REX::TOML::Impl::formatter<double, CharT> {};
129-
template <class CharT> struct formatter<REX::TOML::I8<>, CharT> : REX::TOML::Impl::formatter<std::int8_t, CharT> {};
130-
template <class CharT> struct formatter<REX::TOML::I16<>, CharT> : REX::TOML::Impl::formatter<std::int16_t, CharT> {};
131-
template <class CharT> struct formatter<REX::TOML::I32<>, CharT> : REX::TOML::Impl::formatter<std::int32_t, CharT> {};
132-
template <class CharT> struct formatter<REX::TOML::U8<>, CharT> : REX::TOML::Impl::formatter<std::uint8_t, CharT> {};
133-
template <class CharT> struct formatter<REX::TOML::U16<>, CharT> : REX::TOML::Impl::formatter<std::uint16_t, CharT> {};
134-
template <class CharT> struct formatter<REX::TOML::U32<>, CharT> : REX::TOML::Impl::formatter<std::uint32_t, CharT> {};
135-
template <class CharT> struct formatter<REX::TOML::Str<>, CharT> : REX::TOML::Impl::formatter<std::string, CharT> {};
136-
// clang-format on
137-
}
138-
# endif
113+
return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
114+
}
115+
};
139116
#endif

0 commit comments

Comments
 (0)