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