1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11 |
10 | // <chrono> |
11 | |
12 | #include <chrono> |
13 | #include <type_traits> |
14 | #include <cassert> |
15 | |
16 | #include "test_macros.h" |
17 | |
18 | int main(int, char**) |
19 | { |
20 | using namespace std::literals::chrono_literals; |
21 | |
22 | // Make sure the types are right |
23 | static_assert ( std::is_same<decltype( 3h ), std::chrono::hours>::value, "" ); |
24 | static_assert ( std::is_same<decltype( 3min ), std::chrono::minutes>::value, "" ); |
25 | static_assert ( std::is_same<decltype( 3s ), std::chrono::seconds>::value, "" ); |
26 | static_assert ( std::is_same<decltype( 3ms ), std::chrono::milliseconds>::value, "" ); |
27 | static_assert ( std::is_same<decltype( 3us ), std::chrono::microseconds>::value, "" ); |
28 | static_assert ( std::is_same<decltype( 3ns ), std::chrono::nanoseconds>::value, "" ); |
29 | |
30 | std::chrono::hours h = 4h; |
31 | assert ( h == std::chrono::hours(4)); |
32 | auto h2 = 4.0h; |
33 | assert ( h == h2 ); |
34 | |
35 | std::chrono::minutes min = 36min; |
36 | assert ( min == std::chrono::minutes(36)); |
37 | auto min2 = 36.0min; |
38 | assert ( min == min2 ); |
39 | |
40 | std::chrono::seconds s = 24s; |
41 | assert ( s == std::chrono::seconds(24)); |
42 | auto s2 = 24.0s; |
43 | assert ( s == s2 ); |
44 | |
45 | std::chrono::milliseconds ms = 247ms; |
46 | assert ( ms == std::chrono::milliseconds(247)); |
47 | auto ms2 = 247.0ms; |
48 | assert ( ms == ms2 ); |
49 | |
50 | std::chrono::microseconds us = 867us; |
51 | assert ( us == std::chrono::microseconds(867)); |
52 | auto us2 = 867.0us; |
53 | assert ( us == us2 ); |
54 | |
55 | std::chrono::nanoseconds ns = 645ns; |
56 | assert ( ns == std::chrono::nanoseconds(645)); |
57 | auto ns2 = 645.ns; |
58 | assert ( ns == ns2 ); |
59 | |
60 | |
61 | return 0; |
62 | } |
63 | |