1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // constexpr year operator-(const year& x, const years& y) noexcept;
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]
23 #include <type_traits>
26 #include "test_macros.h"
28 using year
= std::chrono::year
;
29 using years
= std::chrono::years
;
31 constexpr bool test() {
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
);
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
>()));
47 ASSERT_NOEXCEPT(std::declval
<year
>() - std::declval
<year
>());
48 ASSERT_SAME_TYPE(years
, decltype(std::declval
<year
>() - std::declval
<year
>()));
51 static_assert(test());