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 // fractional_width is the number of fractional decimal digits represented by precision.
19 // fractional_width has the value of the smallest possible integer in the range [0, 18]
20 // such that precision will exactly represent all values of Duration.
21 // If no such value of fractional_width exists, then fractional_width is 6.
28 #include "test_macros.h"
30 template <typename Duration
, unsigned width
>
31 constexpr bool check_width()
33 using HMS
= std::chrono::hh_mm_ss
<Duration
>;
34 return HMS::fractional_width
== width
;
39 using microfortnights
= std::chrono::duration
<int, std::ratio
<756, 625>>;
41 static_assert( check_width
<std::chrono::hours
, 0>(), "");
42 static_assert( check_width
<std::chrono::minutes
, 0>(), "");
43 static_assert( check_width
<std::chrono::seconds
, 0>(), "");
44 static_assert( check_width
<std::chrono::milliseconds
, 3>(), "");
45 static_assert( check_width
<std::chrono::microseconds
, 6>(), "");
46 static_assert( check_width
<std::chrono::nanoseconds
, 9>(), "");
47 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 2>>, 1>(), "");
48 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 3>>, 6>(), "");
49 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 4>>, 2>(), "");
50 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 5>>, 1>(), "");
51 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 6>>, 6>(), "");
52 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 7>>, 6>(), "");
53 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 8>>, 3>(), "");
54 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 9>>, 6>(), "");
55 static_assert( check_width
<std::chrono::duration
<int, std::ratio
< 1, 10>>, 1>(), "");
56 static_assert( check_width
<microfortnights
, 4>(), "");