20467
20467
20468
20468
\rSec2[format.formatter]{Formatter}
20469
20469
20470
+ \rSec3[formatter.requirements]{Formatter requirements}
20471
+
20472
+ \pnum
20473
+ \indextext{requirements!\idxnewoldconcept{Formatter}}%
20474
+ A type \tcode{F} meets the \newoldconceptdefn{Formatter} requirements if:
20475
+
20476
+ \begin{itemize}
20477
+ \item
20478
+ it meets the
20479
+ \begin{itemize}
20480
+ \item \oldconcept{DefaultConstructible} (\tref{cpp17.defaultconstructible}),
20481
+ \item \oldconcept{CopyConstructible} (\tref{cpp17.copyconstructible}),
20482
+ \item \oldconcept{CopyAssignable} (\tref{cpp17.copyassignable}), and
20483
+ \item \oldconcept{Destructible} (\tref{cpp17.destructible})
20484
+ \end{itemize}
20485
+ requirements,
20486
+
20487
+ \item
20488
+ it is swappable\iref{swappable.requirements} for lvalues, and
20489
+
20490
+ \item
20491
+ the expressions shown in \tref{formatter} are valid and
20492
+ have the indicated semantics.
20493
+ \end{itemize}
20494
+
20495
+ \pnum
20496
+ Given character type \tcode{charT}, output iterator type
20497
+ \tcode{Out}, and formatting argument type \tcode{T},
20498
+ in \tref{formatter}:
20499
+ \begin{itemize}
20500
+ \item \tcode{f} is a value of type \tcode{F},
20501
+ \item \tcode{u} is an lvalue of type \tcode{T},
20502
+ \item \tcode{t} is a value of a type convertible to (possibly const) \tcode{T},
20503
+ \item \tcode{PC} is \tcode{basic_format_parse_context<charT>},
20504
+ \item \tcode{FC} is \tcode{basic_format_context<Out, charT>},
20505
+ \item \tcode{pc} is an lvalue of type \tcode{PC}, and
20506
+ \item \tcode{fc} is an lvalue of type \tcode{FC}.
20507
+ \end{itemize}
20508
+ \tcode{pc.begin()} points to the beginning of the
20509
+ \fmtgrammarterm{format-spec}\iref{format.string}
20510
+ of the replacement field being formatted
20511
+ in the format string.
20512
+ If \fmtgrammarterm{format-spec} is empty then either
20513
+ \tcode{pc.begin() == pc.end()} or
20514
+ \tcode{*pc.begin() == '\}'}.
20515
+
20516
+ \begin{concepttable}{\newoldconcept{Formatter} requirements}{formatter}
20517
+ {p{1.2in}p{1in}p{2.9in}}
20518
+ \topline
20519
+ \hdstyle{Expression} & \hdstyle{Return type} & \hdstyle{Requirement} \\ \capsep
20520
+ \tcode{f.parse(pc)} &
20521
+ \tcode{PC::iterator} &
20522
+ Parses \fmtgrammarterm{format-spec}\iref{format.string}
20523
+ for type \tcode{T}
20524
+ in the range \range{pc.begin()}{pc.end()}
20525
+ until the first unmatched character.
20526
+ Throws \tcode{format_error} unless the whole range is parsed
20527
+ or the unmatched character is \tcode{\}}.
20528
+ \begin{note}
20529
+ This allows formatters to emit meaningful error messages.
20530
+ \end{note}
20531
+ Stores the parsed format specifiers in \tcode{*this} and
20532
+ returns an iterator past the end of the parsed range.
20533
+ \\ \rowsep
20534
+ \tcode{f.format(t, fc)} &
20535
+ \tcode{FC::iterator} &
20536
+ Formats \tcode{t} according to the specifiers stored in \tcode{*this},
20537
+ writes the output to \tcode{fc.out()} and
20538
+ returns an iterator past the end of the output range.
20539
+ The output shall only depend on
20540
+ \tcode{t},
20541
+ \tcode{fc.locale()},
20542
+ and the range \range{pc.begin()}{pc.end()}
20543
+ from the last call to \tcode{f.parse(pc)}.
20544
+ \\ \rowsep
20545
+ \tcode{f.format(u, fc)} &
20546
+ \tcode{FC::iterator} &
20547
+ As above, but does not modify \tcode{u}.
20548
+ \\
20549
+ \end{concepttable}
20550
+
20470
20551
\rSec3[format.formatter.spec]{Formatter specializations}
20471
20552
\indexlibrary{\idxcode{formatter}}%
20472
20553
@@ -20489,10 +20570,18 @@
20489
20570
\begin{itemize}
20490
20571
\item
20491
20572
\indexlibrary{\idxcode{formatter}!specializations!character types}%
20573
+ The specializations
20574
+ \begin{codeblock}
20575
+ template<> struct formatter<char, char>;
20576
+ template<> struct formatter<char, wchar_t>;
20577
+ template<> struct formatter<wchar_t, wchar_t>;
20578
+ \end{codeblock}
20579
+
20580
+ \item
20492
20581
\indexlibrary{\idxcode{formatter}!specializations!string types}%
20493
20582
For each \tcode{charT},
20583
+ the string type specializations
20494
20584
\begin{codeblock}
20495
- template<> struct formatter<charT, charT>;
20496
20585
template<> struct formatter<charT*, charT>;
20497
20586
template<> struct formatter<const charT*, charT>;
20498
20587
template<size_t N> struct formatter<const charT[N], charT>;
@@ -20503,33 +20592,30 @@
20503
20592
\end{codeblock}
20504
20593
20505
20594
\item
20506
- The specialization
20595
+ \indexlibrary{\idxcode{formatter}!specializations!arithmetic types}%
20596
+ For each \tcode{charT},
20597
+ for each cv-unqualified arithmetic type \tcode{ArithmeticT}
20598
+ other than
20599
+ \tcode{char},
20600
+ \tcode{wchar_t},
20601
+ \tcode{char8_t},
20602
+ \tcode{char16_t}, or
20603
+ \tcode{char32_t},
20604
+ a specialization
20507
20605
\begin{codeblock}
20508
- template<> struct formatter<char, wchar_t >;
20606
+ template<> struct formatter<ArithmeticT, charT >;
20509
20607
\end{codeblock}
20510
20608
20511
20609
\item
20512
- \indexlibrary{\idxcode{formatter}!specializations!arithmetic types}%
20513
20610
\indexlibrary{\idxcode{formatter}!specializations!pointer types}%
20514
20611
\indexlibrary{\idxcode{formatter}!specializations!\idxcode{nullptr_t}}%
20515
- A specialization
20612
+ For each \tcode{charT},
20613
+ the pointer type specializations
20516
20614
\begin{codeblock}
20517
- template<> struct formatter<T, charT>;
20615
+ template<> struct formatter<nullptr_t, charT>;
20616
+ template<> struct formatter<void*, charT>;
20617
+ template<> struct formatter<const void*, charT>;
20518
20618
\end{codeblock}
20519
- for each \tcode{charT},
20520
- for each cv-unqualified type \tcode{T} that is
20521
- \begin{itemize}
20522
- \item \tcode{nullptr_t},
20523
- \item \tcode{void*},
20524
- \item \tcode{const void*},
20525
- \item an integral type other than
20526
- \tcode{char},
20527
- \tcode{wchar_t},
20528
- \tcode{char8_t},
20529
- \tcode{char16_t}, or
20530
- \tcode{char32_t}, or
20531
- \item a floating-point type.
20532
- \end{itemize}
20533
20619
\end{itemize}
20534
20620
The \tcode{parse} member functions of these formatters
20535
20621
interpret the format specification
20590
20676
\end{codeblock}
20591
20677
\end{example}
20592
20678
20593
- \rSec3[formatter.requirements]{Formatter requirements}
20594
-
20595
- \pnum
20596
- \indextext{requirements!\idxnewoldconcept{Formatter}}%
20597
- A type \tcode{F} meets the \newoldconceptdefn{Formatter} requirements if:
20598
-
20599
- \begin{itemize}
20600
- \item
20601
- it meets the
20602
- \begin{itemize}
20603
- \item \oldconcept{DefaultConstructible} (\tref{cpp17.defaultconstructible}),
20604
- \item \oldconcept{CopyConstructible} (\tref{cpp17.copyconstructible}),
20605
- \item \oldconcept{CopyAssignable} (\tref{cpp17.copyassignable}), and
20606
- \item \oldconcept{Destructible} (\tref{cpp17.destructible})
20607
- \end{itemize}
20608
- requirements,
20609
-
20610
- \item
20611
- it is swappable\iref{swappable.requirements} for lvalues, and
20612
-
20613
- \item
20614
- the expressions shown in \tref{formatter} are valid and
20615
- have the indicated semantics.
20616
- \end{itemize}
20617
-
20618
- \pnum
20619
- Given character type \tcode{charT}, output iterator type
20620
- \tcode{Out}, and formatting argument type \tcode{T},
20621
- in \tref{formatter}:
20622
- \begin{itemize}
20623
- \item \tcode{f} is a value of type \tcode{F},
20624
- \item \tcode{u} is an lvalue of type \tcode{T},
20625
- \item \tcode{t} is a value of a type convertible to (possibly const) \tcode{T},
20626
- \item \tcode{PC} is \tcode{basic_format_parse_context<charT>},
20627
- \item \tcode{FC} is \tcode{basic_format_context<Out, charT>},
20628
- \item \tcode{pc} is an lvalue of type \tcode{PC}, and
20629
- \item \tcode{fc} is an lvalue of type \tcode{FC}.
20630
- \end{itemize}
20631
- \tcode{pc.begin()} points to the beginning of the
20632
- \fmtgrammarterm{format-spec}\iref{format.string}
20633
- % FIXME: Which one?
20634
- portion of the format string.
20635
- If \fmtgrammarterm{format-spec} is empty then either
20636
- \tcode{pc.begin() == pc.end()} or
20637
- \tcode{*pc.begin() == '\}'}.
20638
-
20639
- \begin{concepttable}{\newoldconcept{Formatter} requirements}{formatter}
20640
- {p{1.2in}p{1in}p{2.9in}}
20641
- \topline
20642
- \hdstyle{Expression} & \hdstyle{Return type} & \hdstyle{Requirement} \\ \capsep
20643
- \tcode{f.parse(pc)} &
20644
- \tcode{PC::iterator} &
20645
- Parses \fmtgrammarterm{format-spec}\iref{format.string}
20646
- for type \tcode{T}
20647
- in the range \range{pc.begin()}{pc.end()}
20648
- until the first unmatched character.
20649
- Throws \tcode{format_error} unless the whole range is parsed
20650
- or the unmatched character is \tcode{\}}.
20651
- \begin{note}
20652
- This allows formatters to emit meaningful error messages.
20653
- \end{note}
20654
- Stores the parsed format specifiers in \tcode{*this} and
20655
- returns an iterator past the end of the parsed range.
20656
- \\ \rowsep
20657
- \tcode{f.format(t, fc)} &
20658
- \tcode{FC::iterator} &
20659
- Formats \tcode{t} according to the specifiers stored in \tcode{*this},
20660
- writes the output to \tcode{fc.out()} and
20661
- returns an iterator past the end of the output range.
20662
- The output shall only depend on
20663
- \tcode{t},
20664
- \tcode{fc.locale()},
20665
- and the range \range{pc.begin()}{pc.end()}
20666
- from the last call to \tcode{f.parse(pc)}.
20667
- \\ \rowsep
20668
- \tcode{f.format(u, fc)} &
20669
- \tcode{FC::iterator} &
20670
- As above, but does not modify \tcode{u}.
20671
- \\
20672
- \end{concepttable}
20673
-
20674
20679
\rSec3[format.parse.ctx]{Class template \tcode{basic_format_parse_context}}
20675
20680
20676
20681
\indexlibrary{\idxcode{basic_format_parse_context}}%
0 commit comments