56 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: x + -y.15//16// constexpr years operator-(const year& x, const year& y) noexcept;17// Returns: If x.ok() == true and y.ok() == true, returns a value m in the range18// [years{0}, years{11}] satisfying y + m == x.19// Otherwise the value returned is unspecified.20// [Example: January - February == years{11}. -end example]21 22#include <chrono>23#include <cassert>24#include <type_traits>25#include <utility>26 27#include "test_macros.h"28 29using year = std::chrono::year;30using years = std::chrono::years;31 32constexpr bool test() {33 year y{1223};34 for (int i = 1100; i <= 1110; ++i) {35 year y1 = y - years{i};36 years ys1 = y - year{i};37 assert(static_cast<int>(y1) == 1223 - i);38 assert(ys1.count() == 1223 - i);39 }40 41 return true;42}43 44int main(int, char**) {45 ASSERT_NOEXCEPT(std::declval<year>() - std::declval<years>());46 ASSERT_SAME_TYPE(year, decltype(std::declval<year>() - std::declval<years>()));47 48 ASSERT_NOEXCEPT(std::declval<year>() - std::declval<year>());49 ASSERT_SAME_TYPE(years, decltype(std::declval<year>() - std::declval<year>()));50 51 test();52 static_assert(test());53 54 return 0;55}56