brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 252f503 Raw
65 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 9// <chrono>10 11// duration12 13// template <class Rep2>14//   explicit duration(const Rep2& r);15 16#include <chrono>17#include <cassert>18#include <ratio>19 20#include "test_macros.h"21#include "../../rep.h"22 23#if TEST_STD_VER >= 1124struct NotValueConvertible {25    operator int() const&& = delete;26    constexpr operator int() const& { return 1; }27};28#endif29 30template <class D, class R>31TEST_CONSTEXPR_CXX14 void check(R r) {32    D d(r);33    assert(d.count() == r);34}35 36TEST_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);41 42    // test for [time.duration.cons]/143#if TEST_STD_VER >= 1144    check<std::chrono::duration<int> >(NotValueConvertible());45#endif46 47    return true;48}49 50int main(int, char**) {51    test();52#if TEST_STD_VER > 1153    static_assert(test(), "");54#endif55 56    // Basic test for constexpr-friendliness in C++1157#if TEST_STD_VER >= 1158    {59        constexpr std::chrono::duration<int> d(5);60        static_assert(d.count() == 5, "");61    }62#endif63    return 0;64}65