This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::chrono::duration operator<< ???
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Germán Diago <germandiago at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sat, 16 Jan 2010 18:48:45 +0000
- Subject: Re: std::chrono::duration operator<< ???
- References: <b798010f1001161000o472041eah75f732352776c05c@mail.gmail.com>
2010/1/16 Germán Diago:
> Hello. I'm using the chrono library and I want to output a
> time_duration. I can't.
>
> I think it's not planned to include operator<< in std::chrono.
Correct. As far as I know noone has proposed output operators for durations.
> I think it SHOULD be included, since outputting this value will be
> quite common I think.
The obvious question is how should they be output? A format that is
right for your program will be wrong for someone else's program, so
it's difficult to standardise. Should duration<long, milli>(500) be
formatted as "0.5" or "0.5s" or "500ms" or "500 milliseconds" or
"500000000ns" or something else? There's no right answer.
You could propose that the next C++ standard includes a library for
formatting durations, but this is not the right place to do that, and
a proposal would probably be turned down for being too late. It could
be considered for TR2, the second library technical report, but that
is likely to be several years away.
> I tried conversions to long, long long and int and I can't. How can I
> output a duration?
You'll need to write your own output function, using whatever format
is relevant for the durations you use.
Jonathan