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};
template <>
struct fmt::formatter<color>: formatter<string_view> {
template <> struct fmt::formatter<color>: formatter<string_view> {
// parse is inherited from formatter<string_view>.
template <typename FormatContext>
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::
#include <type_traits>