11
22== `ct_format.hpp`
33
4+ === ct_format
5+
46https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/ct_format.hpp[`ct_format.hpp`]
57provides `ct_format`, a compile-time function for formatting strings.
68
@@ -20,7 +22,7 @@ auto s = stdx::ct_format<"Hello {} {}">(42, 17);
2022----
2123
2224When format arguments are available at compile-time, wrapping them in
23- `CX_VALUE(...)` means they will get compile-time formatted.
25+ xref:utility.adoc#_cx_value[ `CX_VALUE(...)`] means they will get compile-time formatted.
2426[source,cpp]
2527----
2628auto s = stdx::ct_format<"Hello {} {}">(CX_VALUE(42), 17);
@@ -69,3 +71,31 @@ constexpr static auto a = stdx::ct_format<"The answer is {}">(42);
6971constexpr static auto q = stdx::ct_format<"{}. But what is the question?">(CX_VALUE(a));
7072// q is stdx::format_result{"The answer is {}. But what is the question?"_ctst, stdx::tuple{42}}
7173----
74+
75+ === STDX_CT_FORMAT
76+
77+ The macro `STDX_CT_FORMAT` will automatically wrap compile-time-friendly
78+ arguments, so manual wrapping with `CX_VALUE` is not required.
79+ [source,cpp]
80+ ----
81+ auto s = STDX_CT_FORMAT("Hello {} {}", 42, int);
82+ // equivalent to stdx::ct_format<"Hello {} {}">(CX_VALUE(42), CX_VALUE(int));
83+ // s is stdx::format_result{"Hello 42 int"_ctst, stdx::tuple{}}
84+ ----
85+
86+ If any arguments are _not_ available at compile time, they will be "regular" runtime format arguments.
87+ [source,cpp]
88+ ----
89+ auto x = 42;
90+ auto s = STDX_CT_FORMAT("Hello {} {}", x, int);
91+ // equivalent to stdx::ct_format<"Hello {} {}">(x, CX_VALUE(int));
92+ // s is stdx::format_result{"Hello {} int"_ctst, stdx::tuple{42}}
93+ ----
94+
95+ Things that are "compile-time-friendly" include:
96+
97+ * `constexpr static` variables
98+ * `const` integral variables
99+ * template arguments
100+ * literals
101+ * types
0 commit comments