@@ -11,62 +11,55 @@ The format string is provided as a template argument, and the arguments to be
1111formatted as regular function arguments.
1212
1313The result type is a `stdx::format_result` containing two members: the
14- xref:ct_string.adoc#_ct_string_hpp[`ct_string`] and a
14+ xref:ct_string.adoc#_ct_string_hpp[`ct_string`] (wrapped in a `cts_t`) and a
1515xref:tuple.adoc#_tuple_hpp[`tuple`] of the format arguments.
1616[source,cpp]
1717----
1818auto s = stdx::ct_format<"Hello {} {}">(42, 17);
19- // s is stdx::format_result{"Hello {} {}"_cts , stdx::tuple{42, 17}}
19+ // s is stdx::format_result{"Hello {} {}"_ctst , stdx::tuple{42, 17}}
2020----
2121
2222When format arguments are available at compile-time, wrapping them in
2323`CX_VALUE(...)` means they will get compile-time formatted.
2424[source,cpp]
2525----
2626auto s = stdx::ct_format<"Hello {} {}">(CX_VALUE(42), 17);
27- // s is stdx::format_result{"Hello 42 {}"_cts , stdx::tuple{17}}
27+ // s is stdx::format_result{"Hello 42 {}"_ctst , stdx::tuple{17}}
2828----
2929
30- If there are no runtime arguments, the result is just a `stdx::ct_string`:
30+ If there are no runtime arguments, the result is a `format_result` with an empty tuple...
3131[source,cpp]
3232----
3333auto s = stdx::ct_format<"Hello {} {}">(CX_VALUE(42), CX_VALUE(17));
34- // s is "Hello 42 17"_cts
34+ // s is stdx::format_result{"Hello 42 17"_ctst, stdx::tuple{}}
35+ ----
36+ ...and a `format_result` like this without an runtime arguments is implicitly convertible back to a `ct_string`:
37+ [source,cpp]
38+ ----
39+ template <stdx::ct_string S> auto f() { ... };
40+
41+ f<stdx::ct_format<"Hello {}">(CX_VALUE(42))>(); // equivalent to f<"Hello 42">()
3542----
3643
3744Types and compile-time enumeration values are stringified thus:
3845[source,cpp]
3946----
4047enum struct E { value };
4148auto s = stdx::ct_format<"Hello {} {}">(CX_VALUE(int), CX_VALUE(E::value));
42- // s is "Hello int value"_cts
49+ // s is stdx::format_result{ "Hello int value"_ctst, stdx::tuple{}}
4350----
4451
4552NOTE: Compile-time formatting is done with https://github.com/fmtlib/fmt[fmtlib]
4653and supports the same formatting DSL. Positional arguments are not supported.
4754
48- `ct_format` is designed for use with a logging backend like the one in
49- https://github.com/intel/compile-time-init-build. Hence `stdx::format_result`
50- allows lazy runtime formatting. For the same reason, compile-time formatting can
51- output string information in a
52- https://github.com/intel/compile-time-init-build/tree/main/include/sc[suitable
53- type] rather than as a value. This is done by passing the template as a second
54- template argument to `ct_format`.
55-
56- [source,cpp]
57- ----
58- auto s = stdx::ct_format<"{}", sc::string_constant>(CX_VALUE(42));
59- // s is sc::string_constant<char, '4', '2'>{}
60- ----
61-
6255When formatting a compile-time `stdx::format_result`, the strings and argument
6356tuples are collapsed to a single `stdx::format_result`:
6457
6558[source,cpp]
6659----
6760constexpr static auto a = stdx::ct_format<"The answer is {}">(42);
68- // a is stdx::format_result{"The answer is {}", stdx::tuple{42}}
61+ // a is stdx::format_result{"The answer is {}"_ctst , stdx::tuple{42}}
6962
7063constexpr static auto q = stdx::ct_format<"{}. But what is the question?">(CX_VALUE(a));
71- // q is stdx::format_result{"The answer is {}. But what is the question?", stdx::tuple{42}}
64+ // q is stdx::format_result{"The answer is {}. But what is the question?"_ctst , stdx::tuple{42}}
7265----
0 commit comments