CppCon 2017: Victor Zverovich “A modern formatting library for C++”

CppCon · 21K views · 2017 · 1:00:55

Open on YouTube

C, C++, Rust, Go & systems languagesSoftware architecture & designtalk

Why Stack Overflow recommends it

Stack Overflow users link it when discussing alternatives to iostream and printf, and the origin and design of {fmt} and std::format.

Recommended by 1 people across 1 different months, 2017 to 2021.

What it is

A one-hour CppCon 2017 talk by Victor Zverovich, author of the fmt library, on C++ text formatting from stdio and iostream to the standard proposal P0645R0. It covers a Python-like format string syntax built on variadic templates, with a focus on performance, extensibility and safety.

What people said

Recommends smoothware · 2018-09 · Stack Overflow · on “What serious alternatives exist for the IOStream library? (besides cstdio)”

The {fmt} library [LINK] : I just stumbled across it from a [this video] and it seems to be quite nice. A formatting facility based on {fmt} has been proposed for standardization in C++20: P0645 [LINK] . Both P0645 and {fmt} use a Python-like format string syntax which is similar to printf 's but uses {} as delimiters instead of % . For example #include <fmt/core.h> int main() { fmt::print("The answer is {}.", 42); } prints "The answer is 42." to stdout . The std::format function proposed for C++20: #include <format> int main() { std::string s = std::format("The answer is {}.", 42); } Notable features of {fmt}: Type and memory safety with errors in format strings optionally reported at compile ti

Cites geza · 2017-11 · Stack Overflow · on “Is there any implementation of type-safe, compile-time checked printf?”

There are attempts [this video] to include a new formatting library into the standard. But doing compile time format string analyzing is not a goal in general. String formatting is usually not a bottleneck. But using your idea, there's a code bloat (compared to printf). In my opinion, if someone wants to create a formatting library, one should focus on: printf style, minimal code size while being fast.

Cites Aykhan Hagverdili · 2021-06 · Stack Overflow · on “How will std::spanstream usually be used in C++?”

@T.C. here [this video] fmt author mentioned that fmt falls back to `operator<<`, so I was recalling that. Perhaps it didn't make its way to C++20, or maybe they removed it down the road. Thank you for pointing out.