Skip to content

Commit 8702a4d

Browse files
committed
make formatter specialisation sexy ⚡
Signed-off-by: TymianekPL <tymi@tymi.org>
1 parent 7a6d53f commit 8702a4d

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

cppjson/include/cppjson/object.hpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,24 @@ namespace cppjson
4444
};
4545
}
4646

47-
namespace std
47+
template<>
48+
struct std::formatter<cppjson::JsonObject>
4849
{
49-
template<>
50-
struct formatter<cppjson::JsonObject>
50+
constexpr auto parse(std::format_parse_context& context)
5151
{
52-
constexpr auto parse(std::format_parse_context& context)
53-
{
54-
return context.begin();
55-
}
52+
return context.begin();
53+
}
5654

57-
auto format(const cppjson::JsonObject& object, std::format_context& context) const
55+
auto format(const cppjson::JsonObject& object, std::format_context& context) const
56+
{
57+
switch (object._dataType)
5858
{
59-
switch (object._dataType)
60-
{
61-
case cppjson::JsonType::Null: return std::format_to(context.out(), "null");
62-
case cppjson::JsonType::Bool: return std::format_to(context.out(), "{}", object.DangerousAs<bool>());
63-
case cppjson::JsonType::Number: return std::format_to(context.out(), "{}", object.DangerousAs<double>());
64-
case cppjson::JsonType::String: return std::format_to(context.out(), "{}", object.DangerousAs<std::string>());
65-
}
66-
67-
throw std::logic_error("Unknown type");
59+
case cppjson::JsonType::Null: return std::format_to(context.out(), "null");
60+
case cppjson::JsonType::Bool: return std::format_to(context.out(), "{}", object.DangerousAs<bool>());
61+
case cppjson::JsonType::Number: return std::format_to(context.out(), "{}", object.DangerousAs<double>());
62+
case cppjson::JsonType::String: return std::format_to(context.out(), "{}", object.DangerousAs<std::string>());
6863
}
69-
};
70-
}
64+
65+
throw std::logic_error("Unknown type");
66+
}
67+
};

0 commit comments

Comments
 (0)