Does the C++ standard library have a templated getter for the printf conversion specifier?

Viewed 112

As we all know, if for some reason you printf() something rather than stream it (which rarely, but sometimes, might happen), you need to specify an appropriate format specifier (d for signed int, u for unsigned, etc. etc.). Now, since printf() is part of the C++ standard library and not just some C legacy, I would hope there might be something like

template <typename T> 
const std::string format_specifier;

Which would allow, say:

template <typename Foo> 
void bar(const Foo& my_foo) {
    printf(format_specifier<Foo>, my_foo);
}

Does the standard library contain something like that?

Notes:

  • Please don't suggest using std::cout, of course that's the default thing you should do. I asked about a function that's part of the standard library; if it were removed from it you could say "this should never ever be used, so your question doesn't matter".
3 Answers
Related