Suppose I've defined some type, e.g.
struct Foo { int a; float b; };
If I want to stream it to an ostream, I write an operator<< function, e.g.:
std::ostream& operator<<(std::ostream& os, const Foo& foo)
{
return os << '(' << a << ',' << b << ')';
}
Now I want to do the same thing, but in an fmt::format() or fmt::print() call. If I write:
fmt::print("{}\n", foo);
I'll get a bunch of errors, ending with something like:
/path/to/fmt/core.h:1073:9: error: static assertion failed: Cannot format argument.
To make type T formattable provide a formatter<T> specialization:
https://fmt.dev/latest/api.html#formatting-user-defined-types
Ok, so, I go there, and I see a bunch of examples, already the first of which is kind of complicated. What's the simplest thing I can write to achieve what I want?