Hi,
I'm using boost.chrono in a project and I need some non-standard input-output.
First of all, I need to print days as days. Consider the following code
namespace testing {
typedef boost::chrono::duration> day;
}
int
main(int argc,char *argv[]) {
using namespace testing;
day d(10.5);
std::cout << "Value: " << d << std::endl;
}
This prints
Value: 10.5 [86400/1]seconds
Which is obviously right; but I'd rather have:
Value 10.5 days
Obviously, a solution is to define operator<<(ostream&,const & day),
however I'd rather use the facet approach, which looks like easier to
extend to parsing and more flexible (e.g. allowing to print the above
value as "10.5 days" somewhere and as "10.5 d" elsewhere.)
If I understand the documentation, I must define a subclass of
boost::chrono::duration_units and then imbue the facet into the
stream. Is this right? Where can I found some guidelines on how to do
that?
Thanks for the help
lc
--
Leo Cacciari
Aliae nationes servitutem pati possunt. Populi Romani est propria libertas.