-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reuse format w/o "reparsing" it? #269
Comments
There is not a cppformat format object (as far as I'm aware). The original idea was based on the python methods of formatting and thus takes the majority of the original design from it. I don't think there was anything in here inspired by Boost. (at least, I haven't seen a single Boost inspired part, but I'm not 100% sure) |
There is no equivalent in C++ Format for this. Moreover, I don't think it's worth doing for the following reasons:
C++ Format is faster than Boost.Format, so you can simply do for (const auto& item : items) {
fmt::format("some complex and long format", item.arg1, item.arg2, ...);
} and this will already be faster than the Boost version. If you want to speed it up, you can avoid fmt::MemoryWriter writer;
for (const auto& item : items) {
writer.write("some complex and long format", item.arg1, item.arg2, ...);
writer.c_str(); // Access the formatted string as a C string to avoid std::string allocation
} To speed this even further you can use the write API: fmt::MemoryWriter writer;
for (const auto& item : items) {
writer << "literal text " << item.arg1 << " more literal text " << item.arg2 << ...;
writer.c_str(); // Access the formatted string as a C string to avoid std::string allocation
} |
thank you for the thorough answer. |
With Boost.Format, I can compile the format once, and use it several times.
Despite CppFormat 2.0 being faster, isn't there an equivalent to the above? Thanks, --DD
The text was updated successfully, but these errors were encountered: