Add full support of format string parsing in compile-time API #2111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some time ago, I wrote that I would try to add support of named arguments in compile-time API here. This took some time... especially when I realize that I can replace most of the functions written by me with functions that already exist in {fmt}.
Some points for the changes:
FMT_COMPILE
and_cf
) parsing functions (compile_format_string()
+parse_tail()
) replaced with the usage offormat_string_compiler
, this gives full support of format string parsing, it's already written and tested code, and that's nicecompile_format_string()
+parse_tail()
functions replaced by two-steps algorithm (kinda):format_part
usingformat_string_compiler
concat<L, R>
){0}
and automatic indexing with{name}
usage works exactly as it works in runtime API (thanks toformat_string_compiler
)compiled_format
types (runtime_named_field
andruntime_named_spec_field
), but these types just hold name or name+specs to be able to usewrite()
function or to createformatter
for specified specs*index
argument kind divided intoindex_auto
andindex_manual
to have meta info about how the argument was created, maybe it's not the best solution, but this meta info needed for properspec_field
creationI was afraid of making compilation time significantly longer by using the current approach, so I made a very straightforward test by compiling
compile-test.cc
with the same tests (master
version of this file) several times, here are average times (mean ± σ, big thanks to hyperfine):-g
-O3 -DNDEBUG
-g
-O3 -DNDEBUG
So, there is some compilation time increase (in most cases), but I'm not sure how bad it is.