brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 1041c33 Raw
50 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 10// <chrono>11// class year;12 13// constexpr year& operator+=(const years& d) noexcept;14// constexpr year& operator-=(const years& d) noexcept;15 16#include <chrono>17#include <cassert>18#include <type_traits>19#include <utility>20 21#include "test_macros.h"22 23using year  = std::chrono::year;24using years = std::chrono::years;25 26constexpr bool test() {27  for (int i = 10000; i <= 10020; ++i) {28    year yr(i);29    assert(static_cast<int>(yr += years{10}) == i + 10);30    assert(static_cast<int>(yr) == i + 10);31    assert(static_cast<int>(yr -= years{9}) == i + 1);32    assert(static_cast<int>(yr) == i + 1);33  }34 35  return true;36}37 38int main(int, char**) {39  ASSERT_NOEXCEPT(std::declval<year&>() += std::declval<years>());40  ASSERT_NOEXCEPT(std::declval<year&>() -= std::declval<years>());41 42  ASSERT_SAME_TYPE(year&, decltype(std::declval<year&>() += std::declval<years>()));43  ASSERT_SAME_TYPE(year&, decltype(std::declval<year&>() -= std::declval<years>()));44 45  test();46  static_assert(test());47 48  return 0;49}50