brintos

brintos / llvm-project-archived public Read only

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