mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-11 21:38:05 +00:00
Clarify formatter reuse
This commit is contained in:
parent
56bc86ffac
commit
b8fbcec1be
12
doc/api.rst
12
doc/api.rst
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user