#include #include // 类型 T 的包装 template struct Box { T value; }; // 能用被包装值的格式说明格式化包装 Box template struct std::formatter, CharT> : std::formatter { // 从基类继承 parse() // 通过以被包装值调用基类实现定义 format() template auto format(Box t, FormatContext& fc) { return std::formatter::format(t.value, fc); } }; int main() { Box v = { 42 }; std::cout << std::format("{:#x}", v); }