Summary
Jason provides a quick introduction to creating custom formatters for std::format and std::print in C++20/23. He demonstrates the simplest possible implementation by specializing std::formatter for a custom type and implementing the format member function using format_to. The episode emphasizes that while custom format string parsing is possible (requiring a constexpr parse function and const format function), the basic approach of just implementing format() is sufficient to get started. Invalid format strings are caught at compile time, demonstrating the power of constexpr validation.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[format.functions]71% match -
[format.formatter.spec]58% match -
[format.context]56% match -
[format.fmt.string]56% match -
[format.formatter.locking]53% match -
[fs.path.fmtr.general]51% match -
[format.range.fmtstr]50% match -
[pointer.conversion]50% match -
[fs.path.native.obs]50% match -
[fs.path.generic.obs]50% match - + 6 more related sections