I used this:
inline static std::string FormatString()
{
return std::string();
}
inline static std::string FormatString(const char* szMessage)
{
return szMessage;
}
template<typename Type1>
static std::string FormatString(const char* formatString, const Type1& arg1)
{
using namespace boost::io;
boost::format formatter(formatString);
formatter % arg1;
return boost::str( formatter );
}
template<typename Type1, typename Type2>
static std::string FormatString(const char* formatString, const Type1& arg1, const Type2& arg2)
{
using namespace boost::io;
boost::format formatter(formatString);
formatter % arg1 % arg2;
return boost::str( formatter );
}
template<typename Type1, typename Type2, typename Type3>
static std::string FormatString(const char* formatString, const Type1& arg1, const Type2& arg2, const Type3& arg3)
{
using namespace boost::io;
boost::format formatter(formatString);
formatter % arg1 % arg2 % arg3;
return boost::str( formatter );
}
I guess it doesn't use varargs, as you requested, but do you often need to go above 10 or so arguments? Maybe there’s some kind of macromagic that would do what you would like, but are mistaken ... this magic, so you might be better off just writing all the versions.
source
share