1 | // explore_limits.cpp ----------------------------------------------------------// |
2 | |
3 | // Copyright 2008 Howard Hinnant |
4 | // Copyright 2008 Beman Dawes |
5 | // Copyright 2009 Vicente J. Botet Escriba |
6 | |
7 | // Distributed under the Boost Software License, Version 1.0. |
8 | // See http://www.boost.org/LICENSE_1_0.txt |
9 | |
10 | /* |
11 | This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which |
12 | was derived by Beman Dawes from Howard Hinnant's time2_demo prototype. |
13 | Many thanks to Howard for making his code available under the Boost license. |
14 | The original code was modified to conform to Boost conventions and to section |
15 | 20.9 Time utilities [time] of the C++ committee's working paper N2798. |
16 | See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. |
17 | |
18 | time2_demo contained this comment: |
19 | |
20 | Much thanks to Andrei Alexandrescu, |
21 | Walter Brown, |
22 | Peter Dimov, |
23 | Jeff Garland, |
24 | Terry Golubiewski, |
25 | Daniel Krugler, |
26 | Anthony Williams. |
27 | */ |
28 | |
29 | #include <boost/chrono/chrono.hpp> |
30 | #include <boost/type_traits.hpp> |
31 | |
32 | #include <iostream> |
33 | |
34 | using namespace boost::chrono; |
35 | |
36 | |
37 | void explore_limits() |
38 | { |
39 | typedef duration<long long, boost::ratio_multiply<boost::ratio<24*3652425,10000>, |
40 | hours::period>::type> Years; |
41 | #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY |
42 | steady_clock::time_point t1( Years(250)); |
43 | steady_clock::time_point t2(-Years(250)); |
44 | #else |
45 | system_clock::time_point t1( Years(250)); |
46 | system_clock::time_point t2(-Years(250)); |
47 | #endif |
48 | // nanosecond resolution is likely to overflow. "up cast" to microseconds. |
49 | // The "up cast" trades precision for range. |
50 | microseconds d = time_point_cast<microseconds>(t: t1) - time_point_cast<microseconds>(t: t2); |
51 | std::cout << d.count() << " microseconds\n" ; |
52 | } |
53 | |
54 | |
55 | int main() |
56 | { |
57 | explore_limits(); |
58 | return 0; |
59 | } |
60 | |
61 | |