Home | History | Annotate | Download | only in time.duration.nonmember
      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 //   typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
     17 //   operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
     18 
     19 #include <chrono>
     20 #include <cassert>
     21 
     22 #include "test_macros.h"
     23 
     24 int main()
     25 {
     26     {
     27     std::chrono::nanoseconds ns1(15);
     28     std::chrono::nanoseconds ns2(6);
     29     std::chrono::nanoseconds r = ns1 % ns2;
     30     assert(r.count() == 3);
     31     }
     32     {
     33     std::chrono::microseconds us1(15);
     34     std::chrono::nanoseconds ns2(28);
     35     std::chrono::nanoseconds r = us1 % ns2;
     36     assert(r.count() == 20);
     37     }
     38     {
     39     std::chrono::duration<int, std::ratio<3, 5> > s1(6);
     40     std::chrono::duration<int, std::ratio<2, 3> > s2(3);
     41     std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2;
     42     assert(r.count() == 24);
     43     }
     44 #if TEST_STD_VER >= 11
     45     {
     46     constexpr std::chrono::nanoseconds ns1(15);
     47     constexpr std::chrono::nanoseconds ns2(6);
     48     constexpr std::chrono::nanoseconds r = ns1 % ns2;
     49     static_assert(r.count() == 3, "");
     50     }
     51     {
     52     constexpr std::chrono::microseconds us1(15);
     53     constexpr std::chrono::nanoseconds ns2(28);
     54     constexpr std::chrono::nanoseconds r = us1 % ns2;
     55     static_assert(r.count() == 20, "");
     56     }
     57     {
     58     constexpr std::chrono::duration<int, std::ratio<3, 5> > s1(6);
     59     constexpr std::chrono::duration<int, std::ratio<2, 3> > s2(3);
     60     constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2;
     61     static_assert(r.count() == 24, "");
     62     }
     63 #endif
     64 }
     65