Clarify formatter reuse

This commit is contained in:
Victor Zverovich 2020-04-22 09:15:52 -07:00
parent 56bc86ffac
commit b8fbcec1be

View File

@ -179,8 +179,7 @@ example::
enum class color {red, green, blue}; enum class color {red, green, blue};
template <> template <> struct fmt::formatter<color>: formatter<string_view> {
struct fmt::formatter<color>: formatter<string_view> {
// parse is inherited from formatter<string_view>. // parse is inherited from formatter<string_view>.
template <typename FormatContext> template <typename FormatContext>
auto format(color c, FormatContext& ctx) { auto format(color c, FormatContext& ctx) {
@ -194,6 +193,15 @@ example::
} }
}; };
Since `parse` is inherited from `formatter<string_view>` it will recognize all
string format specifications, for example
.. code-block:: c++
fmt::format("{:>10}", color::blue)
will return " blue".
You can also write a formatter for a hierarchy of classes:: You can also write a formatter for a hierarchy of classes::
#include <type_traits> #include <type_traits>