mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-23 10:50: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};
|
||||
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user