I'm kinda loathe to use a fixed-sized buffer and the vnsprintf usual suspects.
Would something like this work to have boost::format work with a variable argument list?
Sadly, I cannot use anything from C++11.
void formatIt(const char* msg, ...) {
va_list args;
va_start(args, msg);
boost::format f(msg);
for loop somehow {
f % va_arg(args, const char *); //does this work?
}
va_end(args);
}
I use this:
inline static std::string FormatStringRecurse(boost::format& message)
{
return message.str();
}
template <typename TValue, typename... TArgs>
std::string FormatStringRecurse(boost::format& message, TValue&& arg, TArgs&&... args)
{
message % std::forward<TValue>(arg);
return FormatStringRecurse(message, std::forward<TArgs>(args)...);
}
template <typename... TArgs>
std::string FormatString(const char* fmt, TArgs&&... args)
{
using namespace boost::io;
boost::format message(fmt);
return FormatStringRecurse(message, std::forward<TArgs>(args)...);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With