Hi Ruben!

On Mon, Jul 15, 2013 at 3:41 AM, Ruben Van Boxem
<[email protected]> wrote:
> 2013/7/5 K. Frank <[email protected]>
>
>> Hello List!
>>
>> The following code snippet fails to compile:
>>
>>    auto us = std::chrono::microseconds(7);
>>    std::cout << us << std::endl;   // error
>>
>> (But "std::cout << us.count() << std::endl;" works as expected.)
>>
>> So it looks like std::chrono::duration isn't set up for "<<".
>>
>> Stroustrup's c++11 faq:
>>
>>    http://www.stroustrup.com/C++11FAQ.html
>>
>> suggests that something like this should work:
>>
>>    nanoseconds d = monotonic_clock::now() - t;  // we want the result
>> in nanoseconds
>>    cout << "something took " << d << "nanoseconds\n";
>>
>> Should I be able to insert a std::chrono::duration into an ostream?
>> ...
>
> Both GCC 4.8 with libstdc++:
> http://coliru.stacked-crooked.com/view?id=71573ce00efe8788aa6fcd371fd4e2c0-92a6b8b905b3338bdfc1eb08c231d068
> and clang 3.3 with libc++:
> http://coliru.stacked-crooked.com/view?id=71573ce00efe8788aa6fcd371fd4e2c0-5850791944d571e696c4e044384770e7
> show what you are doing isn't right.

Yes, I've come to the same conclusion.

> I don't have the willpower to dig up a
> Standard quote,

I haven't been able to find any reference to inserting a duration
into an ostream in the standard, so I conclude that you can't.

(It's the problem of proving a negative.  I don't expect to find a
statement in the standard saying that you can't do it.  Also,
such a feature, e.g., operator<<(ostream, duration) could, in
principle, be defined anywhere in the standard, although I would
expect to find it in the duration section, and I've looked through
that section fairly carefully.)

I think that the c++11 faq example I cited is just a typo; a later
example inserts duration.count().

> but this page might give you some hints on how to output
> <chrono> durations:
> http://en.cppreference.com/w/cpp/chrono/duration
>
> Keep that website bookmarked, it's an awesome reference.

Yes, good reference.  Thanks.

> Ruben


Best.


K. Frank

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to