|
Boost : |
Subject: [boost] [format] convenient format wrapper
From: Alexey Klimkin (klimkin_at_[hidden])
Date: 2013-09-06 16:11:24
I found this boost::format wrapper to be very convenient as replacement of
sprintf. Can something like that be a part of the library?
#include <boost/format.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
format&
my_format(format& fmter)
{
return fmter;
}
template <typename T, typename... Args> format&
my_format(format& fmter, T value, Args... args)
{
fmter % value;
return my_format(fmter, args...);
}
string
my_format(string fmt)
{
format fmter(fmt);
return my_format(fmter).str();
}
template <typename... Args> string
my_format(string fmt, Args... args)
{
format fmter(fmt);
return my_format(fmter, args...).str();
}
int
main()
{
cout << my_format("%s %.6f", "pi", 3.14159) << endl;
return 0;
}
-Alexey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk