54 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 year& x, const years& y) noexcept;14// Returns: year(int{x} + y.count()).15//16// constexpr year operator+(const years& x, const year& y) noexcept;17// Returns: y + x18 19#include <chrono>20#include <cassert>21#include <type_traits>22#include <utility>23 24#include "test_macros.h"25 26using year = std::chrono::year;27using years = std::chrono::years;28 29constexpr bool test() {30 year y{1223};31 for (int i = 1100; i <= 1110; ++i) {32 year y1 = y + years{i};33 year y2 = years{i} + y;34 assert(y1 == y2);35 assert(static_cast<int>(y1) == i + 1223);36 assert(static_cast<int>(y2) == i + 1223);37 }38 39 return true;40}41 42int main(int, char**) {43 ASSERT_NOEXCEPT(std::declval<year>() + std::declval<years>());44 ASSERT_SAME_TYPE(year, decltype(std::declval<year>() + std::declval<years>()));45 46 ASSERT_NOEXCEPT(std::declval<years>() + std::declval<year>());47 ASSERT_SAME_TYPE(year, decltype(std::declval<years>() + std::declval<year>()));48 49 test();50 static_assert(test());51 52 return 0;53}54