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 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // template <class Duration>
15 // static unsigned constexpr fractional_width = see below;
16 // using precision = see below;
18 // precision is duration<common_type_t<Duration::rep, seconds::rep>,
19 // ratio<1, 10^^fractional_width>>
24 #include <type_traits>
26 #include "test_macros.h"
28 constexpr unsigned long long powers
[] = {
46 100000000000000000ULL,
47 1000000000000000000ULL,
48 10000000000000000000ULL
51 template <typename Duration
, unsigned width
>
52 constexpr bool check_precision()
54 using HMS
= std::chrono::hh_mm_ss
<Duration
>;
55 using CT
= std::common_type_t
<typename
Duration::rep
, std::chrono::seconds::rep
>;
56 using Pre
= std::chrono::duration
<CT
, std::ratio
<1, powers
[width
]>>;
57 return std::is_same_v
<typename
HMS::precision
, Pre
>;
62 using microfortnights
= std::chrono::duration
<int, std::ratio
<756, 625>>;
64 static_assert( check_precision
<std::chrono::hours
, 0>(), "");
65 static_assert( check_precision
<std::chrono::minutes
, 0>(), "");
66 static_assert( check_precision
<std::chrono::seconds
, 0>(), "");
67 static_assert( check_precision
<std::chrono::milliseconds
, 3>(), "");
68 static_assert( check_precision
<std::chrono::microseconds
, 6>(), "");
69 static_assert( check_precision
<std::chrono::nanoseconds
, 9>(), "");
70 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 2>>, 1>(), "");
71 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 3>>, 6>(), "");
72 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 4>>, 2>(), "");
73 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 5>>, 1>(), "");
74 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 6>>, 6>(), "");
75 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 7>>, 6>(), "");
76 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 8>>, 3>(), "");
77 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 9>>, 6>(), "");
78 static_assert( check_precision
<std::chrono::duration
<int, std::ratio
< 1, 10>>, 1>(), "");
79 static_assert( check_precision
<microfortnights
, 4>(), "");