From 94d387cd4526c3d3179098bf2ae60d653aac07d8 Mon Sep 17 00:00:00 2001
From: Victor Zverovich
Extensibility
Locale Support
+ Positional Arguments
Wording
References
'{'
and
+and Rust [5]. This syntax employs '{'
and
'}'
as replacement field delimiters instead of '%'
and it is described in details in TODO:link. Here are some of the advantages:
@@ -149,6 +150,8 @@ and the new syntax is given in the following table.
printf
. Notable difference is in
the alignment specification. The proposed syntax allows left, center, and right
alignment represented by '<'
, '^'
, and
'>'
respectively which is more expressive than the corresponding
-printf
syntax.
+printf
syntax. The latter only supports left and right (the default)
+alignment.
+
+
+
+The following example uses center alignment and '*'
as a fill
+character:
+
+std::format("{:*^30}", "centered");
+
+
+
+resulting in "***********centered***********"
.
+The same formatting cannot be easily achieved with printf
.
-Both format string syntax and API are designed with extensibility in mind. +Both the format string syntax and the API are designed with extensibility in mind. The mini-language can be extended for user-defined types and users can provide functions that do parsing and formatting for such types.
@@ -215,14 +233,25 @@ functions that do parsing and formatting for such types.
where format-spec is predefined for built-in types, but can be
-customized for user-defined types. For example, time formatting
+customized for user-defined types. For example, the syntax can be extended
+for put_time
-like date and time formatting:
+
+std::time_t t = std::time(nullptr);
+std::string date = std::format("The date is {0:%Y-%m-%d}.", *std::localtime(&t));
+
+
+TODO: API
TODO
+TODO
+TODO