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

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