From b8fbcec1be2e42ea63fccc57d7cada7b09aad500 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 22 Apr 2020 09:15:52 -0700 Subject: [PATCH] Clarify formatter reuse --- doc/api.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 4d221195..0408a2c8 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -179,8 +179,7 @@ example:: enum class color {red, green, blue}; - template <> - struct fmt::formatter: formatter { + template <> struct fmt::formatter: formatter { // parse is inherited from formatter. template auto format(color c, FormatContext& ctx) { @@ -194,6 +193,15 @@ example:: } }; +Since `parse` is inherited from `formatter` 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:: #include