Home | History | Annotate | Download | only in time.duration.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 // duration
     13 
     14 // template <class Rep1, class Period1, class Rep2, class Period2>
     15 //   constexpr
     16 //   bool
     17 //   operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
     18 
     19 // template <class Rep1, class Period1, class Rep2, class Period2>
     20 //   constexpr
     21 //   bool
     22 //   operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
     23 
     24 #include <chrono>
     25 #include <cassert>
     26 
     27 int main()
     28 {
     29     {
     30     std::chrono::seconds s1(3);
     31     std::chrono::seconds s2(3);
     32     assert(s1 == s2);
     33     assert(!(s1 != s2));
     34     }
     35     {
     36     std::chrono::seconds s1(3);
     37     std::chrono::seconds s2(4);
     38     assert(!(s1 == s2));
     39     assert(s1 != s2);
     40     }
     41     {
     42     std::chrono::milliseconds s1(3);
     43     std::chrono::microseconds s2(3000);
     44     assert(s1 == s2);
     45     assert(!(s1 != s2));
     46     }
     47     {
     48     std::chrono::milliseconds s1(3);
     49     std::chrono::microseconds s2(4000);
     50     assert(!(s1 == s2));
     51     assert(s1 != s2);
     52     }
     53     {
     54     std::chrono::duration<int, std::ratio<2, 3> > s1(9);
     55     std::chrono::duration<int, std::ratio<3, 5> > s2(10);
     56     assert(s1 == s2);
     57     assert(!(s1 != s2));
     58     }
     59     {
     60     std::chrono::duration<int, std::ratio<2, 3> > s1(10);
     61     std::chrono::duration<int, std::ratio<3, 5> > s2(9);
     62     assert(!(s1 == s2));
     63     assert(s1 != s2);
     64     }
     65     {
     66     std::chrono::duration<int, std::ratio<2, 3> > s1(9);
     67     std::chrono::duration<double, std::ratio<3, 5> > s2(10);
     68     assert(s1 == s2);
     69     assert(!(s1 != s2));
     70     }
     71 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
     72     {
     73     constexpr std::chrono::seconds s1(3);
     74     constexpr std::chrono::seconds s2(3);
     75     static_assert(s1 == s2, "");
     76     static_assert(!(s1 != s2), "");
     77     }
     78     {
     79     constexpr std::chrono::seconds s1(3);
     80     constexpr std::chrono::seconds s2(4);
     81     static_assert(!(s1 == s2), "");
     82     static_assert(s1 != s2, "");
     83     }
     84     {
     85     constexpr std::chrono::milliseconds s1(3);
     86     constexpr std::chrono::microseconds s2(3000);
     87     static_assert(s1 == s2, "");
     88     static_assert(!(s1 != s2), "");
     89     }
     90     {
     91     constexpr std::chrono::milliseconds s1(3);
     92     constexpr std::chrono::microseconds s2(4000);
     93     static_assert(!(s1 == s2), "");
     94     static_assert(s1 != s2, "");
     95     }
     96     {
     97     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
     98     constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(10);
     99     static_assert(s1 == s2, "");
    100     static_assert(!(s1 != s2), "");
    101     }
    102     {
    103     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(10);
    104     constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(9);
    105     static_assert(!(s1 == s2), "");
    106     static_assert(s1 != s2, "");
    107     }
    108     {
    109     constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(9);
    110     constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(10);
    111     static_assert(s1 == s2, "");
    112     static_assert(!(s1 != s2), "");
    113     }
    114 #endif
    115 }
    116