brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · adee920 Raw
60 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179// <chrono>10 11// template <class Duration>12// class hh_mm_ss13// {14// public:15//     static unsigned constexpr fractional_width = see below;16//     using precision                            = see below;17//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.22 23 24#include <chrono>25#include <cassert>26#include <ratio>27 28#include "test_macros.h"29 30template <typename Duration, unsigned width>31constexpr bool check_width()32{33    using HMS = std::chrono::hh_mm_ss<Duration>;34    return HMS::fractional_width == width;35}36 37int main(int, char**)38{39    using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>;40 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>(), "");57 58    return 0;59}60