Recently I meet an annoying problem that I want to define functions like this:
std::string my_sprintf(const char* format, ...)
{
va_list args;
va_start(args, format);
...
}
std::string my_sprintf(const std::string& format, ...)
{
va_list args;
va_start(args, format); // error
...
}
But it seems reference value can't be the last parameter when using variable length parameter list.
Is that a way that I can let user use std::string as format string?
Maybe factors or something else that detect std::string and convert it as c_str() would work, but I don't know how to deal with the following variable length parameter list.
Edit: I'm not using variadic template because i'm using vsprintf inside. Maybe avoid using vsprintf and using std::stringstream is an option?