User-defined Types
Learn how to format user-defined types apart from basic types and strings.
We'll cover the following...
To format a user-defined type, I have to specialize the class std::formatter
for my user-defined type. This means, in particular, I have to implement the member functions parse
and format
.
-
parse
:- Accepts the parse context
- Parses the parse context
- Returns an iterator to the end of the format specification
- Throws a
std::format_error
in case of an error
-
format
:- Gets the value
t
, which should be formatted, and the format contextfc
- Formats
t
according to the format context - Writes the output to
fc.out()
- Returns an
- Gets the value