| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 |
|
| 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 range |
| 18 |
// [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 <type_traits> |
| 24 |
#include <cassert> |
| 25 |
|
| 26 |
#include "test_macros.h" |
| 27 |
|
| 28 |
using year = std::chrono::year; |
| 29 |
using years = std::chrono::years; |
| 30 |
|
| 31 |
constexpr bool test() { |
| 32 |
year y{1223}; |
| 33 |
for (int i = 1100; i <= 1110; ++i) { |
| 34 |
year y1 = y - years{i}; |
| 35 |
years ys1 = y - year{i}; |
| 36 |
assert(static_cast<int>(y1) == 1223 - i); |
| 37 |
assert(ys1.count() == 1223 - i); |
| 38 |
} |
| 39 |
|
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
int main(int, char**) { |
| 44 |
ASSERT_NOEXCEPT(std::declval<year>() - std::declval<years>()); |
| 45 |
ASSERT_SAME_TYPE(year, decltype(std::declval<year>() - std::declval<years>())); |
| 46 |
|
| 47 |
ASSERT_NOEXCEPT(std::declval<year>() - std::declval<year>()); |
| 48 |
ASSERT_SAME_TYPE(years, decltype(std::declval<year>() - std::declval<year>())); |
| 49 |
|
| 50 |
test(); |
| 51 |
static_assert(test()); |
| 52 |
|
| 53 |
return 0; |
| 54 |
} |