Namespaces
Variants
Views
Actions

C++ named requirements: Formatter

From cppreference.com
< cpp‎ | named req
 
 
C++ named requirements
Basic
Type properties
Library-Wide
Container
Container Elements
Iterator
Stream I/O
Random Numbers
Concurrency
(C++11)

(C++11)
(C++11)
Other
 

Formatter is a type that abstracts formatting operations for a given formatting argument type and character type. Specializations of std::formatter are required to model Formatter.

[edit] Requirements

A type satisfies Formatter if it is semiregular, meaning it satisfies:

And, given

  • Arg, a formatting argument type
  • CharT, a character type
  • Formatter, a Formatter type for types Arg and CharT
  • OutputIt, a LegacyOutputIterator type
  • formatter, a value of type Formatter
  • arg, an lvalue of type Arg
  • t, a value of type convertible to (possibly const) Arg
  • ParseContext, an alias of std::basic_format_parse_context<CharT>
  • FormatContext, an alias of std::basic_format_context<OutputIt, CharT>
  • parse_context, an lvalue of type ParseContext
  • format_context, an lvalue of type FormatContext
Expression Return type Semantics
formatter.parse(parse_context) ParseContext::iterator
  • Parses the format-spec [parse_context.begin(), parse_context.end()) for type Arg until the first unmatched character.
  • Throws std::format_error unless the whole range is parsed or the unmatched character is }. [note 1]
  • Stores the parsed format specifiers in formatter and returns an end iterator of the parsed range.
formatter.format(t, format_context) FormatContext::​iterator
  • Formats t according to the specifiers stored in formatter, writes the output to format_context.out() and returns an end iterator of the output range.
  • The output shall only depend on
    • t,
    • format_context.locale(),
    • the range [parse_context.begin(), parse_context.end()) from the last call to formatter.parse(parse_context), and
    • format_context.arg(n) for any value n of type std::size_t.
formatter.format(arg, format_context) FormatContext::​iterator

As above, but does not modify arg.

  1. This allows formatters to emit meaningful error messages.