All Formatter and Printing Customization Points

All Formatter and Printing Customization Points

A compact scan page for formatter specializations, format context types, and print-oriented customization hooks in modern C++.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

All Formatter and Printing Customization Points

Core formatting customization types

Main formatting entry points

What customization usually means

Practical rules

Small worked example

#include <format>
#include <string_view>

struct Point {
	int x{};
	int y{};
};

template <>
struct std::formatter<Point> : std::formatter<std::string_view> {
	auto format(const Point& point, std::format_context& ctx) const {
		return std::format_to(ctx.out(), "({}, {})", point.x, point.y);
	}
};

The main idea is simple: parse any custom specifiers you want in parse(), then write the formatted output in format(). If you do not need custom specifiers, keep parse() minimal and focus on stable readable output.

Custom-formatting habit

Example in practice

#include <format>
#include <string>

struct Point {
    int x{};
    int y{};
};

template <>
struct std::formatter<Point> : std::formatter<std::string_view> {
    auto format(const Point& point, std::format_context& ctx) const {
        return std::formatter<std::string_view>::format("Point", ctx);
    }
};

int main() {
    return std::format("{}", Point{3, 4}).size();
}