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 Period, class Rep2>
14 //   constexpr
15 //   duration<typename common_type<Rep1, Rep2>::type, Period>
16 //   operator*(const duration<Rep1, Period>& d, const Rep2& s);
17 
18 // template <class Rep1, class Period, class Rep2>
19 //   constexpr
20 //   duration<typename common_type<Rep1, Rep2>::type, Period>
21 //   operator*(const Rep1& s, const duration<Rep2, Period>& d);
22 
23 #include <chrono>
24 #include <cassert>
25 
26 #include "test_macros.h"
27 #include "../../rep.h"
28 
main(int,char **)29 int main(int, char**)
30 {
31     {
32     std::chrono::nanoseconds ns(3);
33     ns = ns * 5;
34     assert(ns.count() == 15);
35     ns = 6 * ns;
36     assert(ns.count() == 90);
37     }
38 
39 #if TEST_STD_VER >= 11
40     {
41     constexpr std::chrono::nanoseconds ns(3);
42     constexpr std::chrono::nanoseconds ns2 = ns * 5;
43     static_assert(ns2.count() == 15, "");
44     constexpr std::chrono::nanoseconds ns3 = 6 * ns;
45     static_assert(ns3.count() == 18, "");
46     }
47 #endif
48 
49 #if TEST_STD_VER >= 11
50     { // This is related to PR#41130
51     typedef std::chrono::nanoseconds Duration;
52     Duration d(5);
53     NotARep n;
54     ASSERT_SAME_TYPE(Duration, decltype(d * n));
55     ASSERT_SAME_TYPE(Duration, decltype(n * d));
56     d = d * n;
57     assert(d.count() == 5);
58     d = n * d;
59     assert(d.count() == 5);
60     }
61 #endif
62 
63   return 0;
64 }
65