1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // template <class Rep2>
14 // explicit duration(const Rep2& r);
20 #include "test_macros.h"
21 #include "../../rep.h"
23 #if TEST_STD_VER >= 11
24 struct NotValueConvertible
{
25 operator int() const&& = delete;
26 constexpr operator int() const& { return 1; }
30 template <class D
, class R
>
31 TEST_CONSTEXPR_CXX14
void check(R r
) {
33 assert(d
.count() == r
);
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);
42 // test for [time.duration.cons]/1
43 #if TEST_STD_VER >= 11
44 check
<std::chrono::duration
<int> >(NotValueConvertible());
50 int main(int, char**) {
53 static_assert(test(), "");
56 // Basic test for constexpr-friendliness in C++11
57 #if TEST_STD_VER >= 11
59 constexpr std::chrono::duration
<int> d(5);
60 static_assert(d
.count() == 5, "");