• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03, c++11
11 // <chrono>
12 
13 #include <chrono>
14 #include <type_traits>
15 #include <cassert>
16 
main()17 int main()
18 {
19     using namespace std::literals::chrono_literals;
20 
21 //    Make sure the types are right
22     static_assert ( std::is_same<decltype( 3h   ), std::chrono::hours>::value, "" );
23     static_assert ( std::is_same<decltype( 3min ), std::chrono::minutes>::value, "" );
24     static_assert ( std::is_same<decltype( 3s   ), std::chrono::seconds>::value, "" );
25     static_assert ( std::is_same<decltype( 3ms  ), std::chrono::milliseconds>::value, "" );
26     static_assert ( std::is_same<decltype( 3us  ), std::chrono::microseconds>::value, "" );
27     static_assert ( std::is_same<decltype( 3ns  ), std::chrono::nanoseconds>::value, "" );
28 
29     std::chrono::hours h = 4h;
30     assert ( h == std::chrono::hours(4));
31     auto h2 = 4.0h;
32     assert ( h == h2 );
33 
34     std::chrono::minutes min = 36min;
35     assert ( min == std::chrono::minutes(36));
36     auto min2 = 36.0min;
37     assert ( min == min2 );
38 
39     std::chrono::seconds s = 24s;
40     assert ( s == std::chrono::seconds(24));
41     auto s2 = 24.0s;
42     assert ( s == s2 );
43 
44     std::chrono::milliseconds ms = 247ms;
45     assert ( ms == std::chrono::milliseconds(247));
46     auto ms2 = 247.0ms;
47     assert ( ms == ms2 );
48 
49     std::chrono::microseconds us = 867us;
50     assert ( us == std::chrono::microseconds(867));
51     auto us2 = 867.0us;
52     assert ( us == us2 );
53 
54     std::chrono::nanoseconds ns = 645ns;
55     assert ( ns == std::chrono::nanoseconds(645));
56     auto ns2 = 645.ns;
57     assert ( ns == ns2 );
58 }
59