Using the C++ fmt library, and given a bare format specifier, is there a way to format a single argument using it?
// example
std::string str = magic_format(".2f", 1.23);
// current method
template <typename T>
std::string magic_format(const std::string spec, const T arg) {
return fmt::format(fmt::format("{{:{}}}", spec), arg);
}
While the above implementation does what I want, I would prefer a way that doesn't require me to build a new temporary string in the process.