1. Introduction
This paper proposes making formattable using the
formatting facility introduced in C++20 ().
2. Motivation
currently has no standard way to be formatted or printed
directly. For example none of this compiles:
std :: cout << std :: generic_category (); std :: ( "{}" , std :: generic_category ());
Additionally the encoding of was unspecified
making it difficult to use it reliably - this is addressed by [P3395].
3. Proposal
The current paper proposes making formattable:
std :: ( "{}" , std :: generic_category ());
This prints .
It will correctly handle width and alignment:
std :: ( "[{:>10}] \n " , std :: generic_category ());
Output:
[ generic ]
Similarly to other recent cases, an ostream inserter is not proposed but it is
possible to stream the string returned by or
the output of .
4. Wording
Add to "Header <system_error> synopsis" [system.error.syn]:
// [system.error.fmt], formatter template < class charT > struct formatter < error_category , charT > ;
Add a new section "Formatting" [system.error.fmt] under "Class " [syserr.errcat]:
template < class charT > struct formatter < error_category , charT > : formatter < basic_string_view < charT > , charT > { template < class FormatContext > typename FormatContext :: iterator format ( const error_category & cat , FormatContext & ctx ) const ; };
template < class FormatContext > typename FormatContext :: iterator format ( const error_category & cat , FormatContext & ctx ) const ;
Let be if is and ,
transcoded to wide literal encoding otherwise.
Returns: .