Format your own type (Part 1) -- Sandor Dargo
I recently published two posts about how C++26 improves
std::format and the related facilities. (If you missed them, here are Part 1 and Part 2). Now it’s time to explore how you can format your own types using std::format.
Format your own type (Part 1)
by Sandor Dargo
From the article:
std::formatwas introduced in C++20 and is based on Victor Zverovich’s<fmt>library, which in turn was inspired by Python’s string formatting capabilities.Let’s skip the fancy formatting options and simply see how to interpolate values using
std::format.
#include <format> #include <iostream> #include <string>int main() { std::string language{"C++"}; int version{20}; std::cout << std::format("{}{} is fun", language, version) << '\n'; }/* C++20 is fun */
That was easy.
Now imagine you want to print your own type. That won’t work by default.


Release 1.89 of the Boost C++ Libraries is now available.
Another year, another trip report from C++ On Sea!
When should a destructor be virtual in C++? In this post, we’ll explore a real-world example from smart pointer implementation to illustrate when virtual destructors are necessary — and when they’re not.
C++26 is bringing a long-awaited feature to the language: compile-time reflection, enabling programs to introspect and manipulate their own structure during compilation. This powerful capability opens the door to eliminating boilerplate, improving performance, and writing more expressive, reusable code with ease.