They do mention "std::print"[2] from C++23 (which uses std::format) and compile times, but, they don't touch on "std::format" at all.
See:
[1] https://en.cppreference.com/w/cpp/utility/format/format.html
The kinds of places still waiting C++ aren’t usually the ones that put much emphasis on using a compiler from the past decade.
Java 8 and C++98 will be here forever lol
Unfortunately, MSVC, always lags and fails to implement some things.
Comparing using `hyperfine --warmup 3 "g++ FILE.cpp"` (and some flags for fmt) I get 72ms vs 198ms. So I changed my mind and might take a crack at replacing {fmt} as well. Cool stuff! Thank you.
[1] https://vitaut.net/posts/2024/faster-cpp-compile-times/
[2] https://godbolt.org/z/3YaovhrjP bench-fmt.cpp
[3] https://godbolt.org/z/qMfM39P3q bench-rikifmt.cpp
char buffer[64];
String_Buffer buf = {str, sizeof str};
Probably meant the "buffer" to be "str" here. char buffer[64];
And then it's not used anywhere!I was curious about the "Why not printf" section, but I found code I don't understand there, too. For example this admittedly non-working snippet is cited as idiomatic:
char str[4] = {0};
int cursor = 0;
cursor += snprintf(str, sizeof str, "hello ");
cursor += snprintf(str, sizeof str, "world!");
Of corse this doesn't work (if the intent was to assemble the "hello world!" string, of which I'm not entirely sure), but not for the reason stated in TFA. You need to actually use cursor, not merely set it! :)For localization you might want numbered holes which makes it way more complicated.
You can detect if the backing buffer is too short, but can you detect other errors? Like having different numbers of holes and arguments? I couldn’t find any discussion about this.
You do still need templates for the arguments (unless you're willing to resort to nasty preprocessor hackery, which would be needed if doing this in C - hmm, are the lifetime-of-temporary rules different too?), but it's pretty easy to just do:
my_asprintf_or_whatever(to_borrowed_primitive(to_owning_primitive(arg))...)
where `to_owning_primitive` is the ADL'ed function you implement for every type you want to print, and `to_borrowed_primitive` probably only needs to be implemented for each string type (though I did find it also useful for wrapped integers of unknown size/rank, such as `time_t`).$"i={i}"
One issue that I had is that printing floating-point values really needs the ability for the user to specify the precision and format. It's actually absurd that `std::to_string(double)` does not allow this.
Also, I believe `std::to_chars(double)` uses a fast algorithm and allows writing directly into a buffer.
In this day and age who knows when a dependency is hijacked :(