| 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 | // <chrono> |
| 10 | |
| 11 | // time_point |
| 12 | |
| 13 | // template <class Clock, class Duration1, class Duration2> |
| 14 | // bool |
| 15 | // operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 16 | |
| 17 | // template <class Clock, class Duration1, class Duration2> |
| 18 | // bool |
| 19 | // operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 20 | |
| 21 | #include <chrono> |
| 22 | #include <cassert> |
| 23 | |
| 24 | #include "test_macros.h" |
| 25 | |
| 26 | int main(int, char**) |
| 27 | { |
| 28 | typedef std::chrono::system_clock Clock; |
| 29 | typedef std::chrono::milliseconds Duration1; |
| 30 | typedef std::chrono::microseconds Duration2; |
| 31 | typedef std::chrono::time_point<Clock, Duration1> T1; |
| 32 | typedef std::chrono::time_point<Clock, Duration2> T2; |
| 33 | |
| 34 | { |
| 35 | T1 t1(Duration1(3)); |
| 36 | T1 t2(Duration1(3)); |
| 37 | assert( (t1 == t2)); |
| 38 | assert(!(t1 != t2)); |
| 39 | } |
| 40 | { |
| 41 | T1 t1(Duration1(3)); |
| 42 | T1 t2(Duration1(4)); |
| 43 | assert(!(t1 == t2)); |
| 44 | assert( (t1 != t2)); |
| 45 | } |
| 46 | { |
| 47 | T1 t1(Duration1(3)); |
| 48 | T2 t2(Duration2(3000)); |
| 49 | assert( (t1 == t2)); |
| 50 | assert(!(t1 != t2)); |
| 51 | } |
| 52 | { |
| 53 | T1 t1(Duration1(3)); |
| 54 | T2 t2(Duration2(3001)); |
| 55 | assert(!(t1 == t2)); |
| 56 | assert( (t1 != t2)); |
| 57 | } |
| 58 | |
| 59 | #if TEST_STD_VER > 11 |
| 60 | { |
| 61 | constexpr T1 t1(Duration1(3)); |
| 62 | constexpr T1 t2(Duration1(3)); |
| 63 | static_assert( (t1 == t2), "" ); |
| 64 | static_assert(!(t1 != t2), "" ); |
| 65 | } |
| 66 | { |
| 67 | constexpr T1 t1(Duration1(3)); |
| 68 | constexpr T1 t2(Duration1(4)); |
| 69 | static_assert(!(t1 == t2), "" ); |
| 70 | static_assert( (t1 != t2), "" ); |
| 71 | } |
| 72 | { |
| 73 | constexpr T1 t1(Duration1(3)); |
| 74 | constexpr T2 t2(Duration2(3000)); |
| 75 | static_assert( (t1 == t2), "" ); |
| 76 | static_assert(!(t1 != t2), "" ); |
| 77 | } |
| 78 | { |
| 79 | constexpr T1 t1(Duration1(3)); |
| 80 | constexpr T2 t2(Duration2(3001)); |
| 81 | static_assert(!(t1 == t2), "" ); |
| 82 | static_assert( (t1 != t2), "" ); |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |