This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::chrono::duration operator<< ???


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]