On 14/11/12 05:06, VinceRev wrote:
> Currently, the standard library defines the following types in std::chrono
>
> std::chrono::nanoseconds / duration type with Period std::nano
> std::chrono::microseconds / duration type with Period std::micro
> std::chrono::milliseconds / duration type with Period std::milli
> std::chrono::seconds / duration type with Period std::ratio<1>
> std::chrono::minutes / duration type with Period std::ratio<60>
> std::chrono::hours / duration type with Period std::ratio<3600>
>
> I think that this list misses two common and well defined durations :
> days and years :
Yes. That was deliberate. These durations are primarily intended for use
with functions that have timeouts, such as std::future<T>::wait_for or
std::this_thread::sleep_for. Such long timeouts would definitely be an
unusual occurrence. Also, longer time periods are often ill-defined, and
have different meanings in different contexts. Even "day" can be subject
to such inconsistencies.
Finally, we deliberately shied away from anything that related to
calendar systems, in anticipation that a future C++ standard would
provide a wider date-time framework. A duration of "3 days" could thus
be specified with reference to that framework if necessary.
> Furthermore I think it could be usefull to be able to specify the Rep
> template parameter of these durations :
> For example std::chrono::hours would be redefined as : template<class
> Rep> std::chrono::hours which is equivalent to
> std::chrono::duration<Rep, std::ratio<3600> >
>
> What is your point of view on that ?
std::duration<> is the template for this; there is no need for
additional templates with pre-specified ratios.
Anthony
--
Author of C++ Concurrency in Action
http://www.stdthread.co.uk/book/
just::thread C++11 thread library
http://www.stdthread.co.uk
Just Software Solutions Ltd
http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976