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// duration
12
13// template <class Rep1, class Period1, class Rep2, class Period2>
14// constexpr
15// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
16// operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
17
18#include <chrono>
19#include <cassert>
20#include <ratio>
21#include "../../rep.h"
22
23#include "test_macros.h"
24
25int main(int, char**)
26{
27 {
28 std::chrono::nanoseconds ns1(15);
29 std::chrono::nanoseconds ns2(6);
30 std::chrono::nanoseconds r = ns1 % ns2;
31 assert(r.count() == 3);
32 }
33 {
34 std::chrono::microseconds us1(15);
35 std::chrono::nanoseconds ns2(28);
36 std::chrono::nanoseconds r = us1 % ns2;
37 assert(r.count() == 20);
38 }
39 {
40 std::chrono::duration<int, std::ratio<3, 5> > s1(6);
41 std::chrono::duration<int, std::ratio<2, 3> > s2(3);
42 std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2;
43 assert(r.count() == 24);
44 }
45#if TEST_STD_VER >= 11
46 {
47 constexpr std::chrono::nanoseconds ns1(15);
48 constexpr std::chrono::nanoseconds ns2(6);
49 constexpr std::chrono::nanoseconds r = ns1 % ns2;
50 static_assert(r.count() == 3, "");
51 }
52 {
53 constexpr std::chrono::microseconds us1(15);
54 constexpr std::chrono::nanoseconds ns2(28);
55 constexpr std::chrono::nanoseconds r = us1 % ns2;
56 static_assert(r.count() == 20, "");
57 }
58 {
59 constexpr std::chrono::duration<int, std::ratio<3, 5> > s1(6);
60 constexpr std::chrono::duration<int, std::ratio<2, 3> > s2(3);
61 constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 % s2;
62 static_assert(r.count() == 24, "");
63 }
64 {
65 std::chrono::duration<int> d(5);
66 RepConstConvertibleLWG3050 x;
67
68 {
69 auto r = d % x;
70 assert(r.count() == 1);
71 ASSERT_SAME_TYPE(std::chrono::duration<long>, decltype(r));
72 }
73 }
74#endif // TEST_STD_VER >= 11
75
76 return 0;
77}
78

source code of libcxx/test/std/time/time.duration/time.duration.nonmember/op_mod_duration.pass.cpp