diff options
Diffstat (limited to 'deimos/core/format.h')
-rw-r--r-- | deimos/core/format.h | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/deimos/core/format.h b/deimos/core/format.h index ba1a3e2..8a2c850 100644 --- a/deimos/core/format.h +++ b/deimos/core/format.h @@ -15,6 +15,12 @@ struct CustomFormatter Callback callback;
};
+template<typename T>
+concept CustomFormattable = requires(IWriter* writer, const T& value)
+{
+ DeimosFormat(writer, value);
+};
+
struct FormatArg
{
enum Type : uint8_t
@@ -50,29 +56,26 @@ struct FormatArg string{value}
{}
- template<typename T>
- constexpr explicit FormatArg(const T& payload, CustomFormatter::Callback callback) :
+ template<CustomFormattable T>
+ constexpr explicit FormatArg(const T& payload) :
type{kCustom},
- custom{CustomFormatter{&payload, callback}}
- {}
+ custom{CustomFormatter{&payload, [](IWriter* writer, const void* raw)
+ {
+ DeimosFormat(writer, *(const T*)raw);
+ }}}
+ {
+ }
};
template<typename T>
-deimos::FormatArg DeimosMakeFormatArg(T&& value)
- requires std::is_constructible_v<deimos::FormatArg, T>
-{
- return deimos::FormatArg(value);
-}
-
-template<typename T>
-concept Formattable = std::same_as<deimos::FormatArg, decltype(DeimosMakeFormatArg(std::declval<T>()))>;
+concept Formattable = std::is_constructible_v<FormatArg, T>;
void FormatVa(IWriter*, gsl::czstring fmt, Span<const FormatArg>);
template<Formattable... Args>
void Format(IWriter* writer, gsl::czstring fmt, Args&&... args)
{
- FormatVa(writer, fmt, { DeimosMakeFormatArg(std::forward<Args>(args))... });
+ FormatVa(writer, fmt, { FormatArg(std::forward<Args>(args))... });
}
} // namespace deimos
|