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 Rep2>
14 // explicit duration(const Rep2& r);
15
16 #include <chrono>
17 #include <cassert>
18 #include <ratio>
19
20 #include "test_macros.h"
21 #include "../../rep.h"
22
23 #if TEST_STD_VER >= 11
24 struct NotValueConvertible {
25 operator int() const&& = delete;
operator intNotValueConvertible26 constexpr operator int() const& { return 1; }
27 };
28 #endif
29
30 template <class D, class R>
check(R r)31 TEST_CONSTEXPR_CXX14 void check(R r) {
32 D d(r);
33 assert(d.count() == r);
34 }
35
test()36 TEST_CONSTEXPR_CXX14 bool test() {
37 check<std::chrono::duration<int> >(5);
38 check<std::chrono::duration<int, std::ratio<3, 2> > >(5);
39 check<std::chrono::duration<Rep, std::ratio<3, 2> > >(Rep(3));
40 check<std::chrono::duration<double, std::ratio<2, 3> > >(5.5);
41
42 // test for [time.duration.cons]/1
43 #if TEST_STD_VER >= 11
44 check<std::chrono::duration<int> >(NotValueConvertible());
45 #endif
46
47 return true;
48 }
49
main(int,char **)50 int main(int, char**) {
51 test();
52 #if TEST_STD_VER > 11
53 static_assert(test(), "");
54 #endif
55
56 // Basic test for constexpr-friendliness in C++11
57 #if TEST_STD_VER >= 11
58 {
59 constexpr std::chrono::duration<int> d(5);
60 static_assert(d.count() == 5, "");
61 }
62 #endif
63 return 0;
64 }
65