brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 51fa2d9 Raw
57 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// constexpr bool is_negative() const noexcept;15 16#include <chrono>17#include <cassert>18#include <ratio>19#include <utility>20 21#include "test_macros.h"22 23template <typename Duration>24constexpr bool check_neg(Duration d)25{26    ASSERT_SAME_TYPE(bool, decltype(std::declval<std::chrono::hh_mm_ss<Duration>>().is_negative()));27    ASSERT_NOEXCEPT(                std::declval<std::chrono::hh_mm_ss<Duration>>().is_negative());28    return std::chrono::hh_mm_ss<Duration>(d).is_negative();29}30 31int main(int, char**)32{33    using microfortnights = std::chrono::duration<int, std::ratio<756, 625>>;34 35    static_assert(!check_neg(std::chrono::minutes( 1)), "");36    static_assert( check_neg(std::chrono::minutes(-1)), "");37 38    assert(!check_neg(std::chrono::seconds( 5000)));39    assert( check_neg(std::chrono::seconds(-5000)));40    assert(!check_neg(std::chrono::minutes( 5000)));41    assert( check_neg(std::chrono::minutes(-5000)));42    assert(!check_neg(std::chrono::hours( 11)));43    assert( check_neg(std::chrono::hours(-11)));44 45    assert(!check_neg(std::chrono::milliseconds( 123456789LL)));46    assert( check_neg(std::chrono::milliseconds(-123456789LL)));47    assert(!check_neg(std::chrono::microseconds( 123456789LL)));48    assert( check_neg(std::chrono::microseconds(-123456789LL)));49    assert(!check_neg(std::chrono::nanoseconds( 123456789LL)));50    assert( check_neg(std::chrono::nanoseconds(-123456789LL)));51 52    assert(!check_neg(microfortnights( 10000)));53    assert( check_neg(microfortnights(-10000)));54 55    return 0;56}57