...
This commit is contained in:
@@ -12,10 +12,14 @@ namespace mcc
|
||||
struct mcc_serializer_interface_t {
|
||||
virtual ~mcc_serializer_interface_t() = default;
|
||||
|
||||
template <std::derived_from<mcc_serializer_interface_t> SelfT, traits::mcc_output_char_range R, typename ValueT>
|
||||
mcc_error_c auto operator()(this SelfT&& self, R& output, ValueT&& value)
|
||||
template <std::derived_from<mcc_serializer_interface_t> SelfT,
|
||||
traits::mcc_output_char_range R,
|
||||
typename ValueT,
|
||||
typename FmtT = std::format_string<ValueT>>
|
||||
requires(std::same_as<FmtT, std::format_string<ValueT>> || std::same_as<FmtT, std::string_view>)
|
||||
mcc_error_c auto operator()(this SelfT&& self, R& output, ValueT&& value, FmtT fmt = "{}")
|
||||
{
|
||||
return std::forward<SelfT>(self).operator=(output, std::forward<ValueT>(value));
|
||||
return std::forward<SelfT>(self).operator=(output, std::forward<ValueT>(value), std::move(fmt));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,6 +27,10 @@ template <typename T>
|
||||
concept mcc_serializer_c = std::derived_from<T, mcc_serializer_interface_t>;
|
||||
|
||||
|
||||
|
||||
template <typename VT>
|
||||
class MccSerializer;
|
||||
|
||||
template <typename VT>
|
||||
class MccSerializer : public mcc_serializer_interface_t
|
||||
{
|
||||
@@ -35,10 +43,15 @@ public:
|
||||
|
||||
~MccSerializer() = default;
|
||||
|
||||
error_t operator()(traits::mcc_output_char_range auto& output, VT&& value)
|
||||
template <typename FmtT = std::format_string<VT>>
|
||||
error_t operator()(traits::mcc_output_char_range auto& output, VT&& value, FmtT fmt = "{}")
|
||||
requires std::formattable<VT, char>
|
||||
{
|
||||
std::format_to(std::back_inserter(output), "{}", value);
|
||||
if constexpr (std::same_as<FmtT, std::format_string<VT>>) {
|
||||
std::format_to(std::back_inserter(output), fmt, value);
|
||||
} else if constexpr (std::same_as<FmtT, std::string_view>) {
|
||||
std::vformat_to(std::back_inserter(output), fmt, std::make_format_args(value));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
@@ -48,7 +61,6 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <mcc_angle_c T>
|
||||
class MccSerializer<T> : public mcc_serializer_interface_t
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user