4 ms·
C++ also has std::format, which was introduced in C++20. This is just sugar on top of it, except it also returns a container type so that printing functions can
by HeliumHydride 2y ago
C++ also has std::format, which was introduced in C++20. This is just sugar on top of it, except it also returns a container type so that printing functions can have overloads that format into a file or stream directly from an f-string, instead of going through the overhead of a temporary string.
- rerdavies 2y agoI'm wonder what this mysterious application is that is doing heavy formatting of strings but can't afford the overhead of a temporary string, and therefore requires horrifying and inscrutable and dangerous language extensions.
- chlorion 2y agoBeing able to use string formatting without a heap is pretty cool. Rusts string formatting machinery does not require any heap allocations at all, you can for example impl fmt::Write for a struct that writes directly to a serial console byte-by-byte with no allocations, and then you have access to all of rusts string formatting features available to print over a serial console! I'm not sure about the horrifying and dangerous extensions part though, I'm not really a C++ expert so I don't know if there's a better way to do what they want to do.
- badmintonbaseba 2y agofreestanding maybe? Embedded apps often don't shy away from using something like printf, yet they don't like unnecessary allocations.
- gpderetta 2y agoFor example, an high performance logger can ship the tuple object to a background thread for actual formatting and I/O, after converting the capture to by-value. Formatting on the foreground thread would be a non-starter.