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
11 // class year_month_day;
13 // constexpr year_month_day& operator+=(const years& d) noexcept;
14 // constexpr year_month_day& operator-=(const years& d) noexcept;
17 #include <type_traits>
20 #include "test_macros.h"
22 using year
= std::chrono::year
;
23 using month
= std::chrono::month
;
24 using day
= std::chrono::day
;
25 using year_month_day
= std::chrono::year_month_day
;
26 using years
= std::chrono::years
;
28 constexpr bool test() {
29 for (int i
= 1000; i
<= 1010; ++i
) {
32 year_month_day
ym(year
{i
}, m
, d
);
33 assert(static_cast<int>((ym
+= years
{2}).year()) == i
+ 2);
34 assert(ym
.month() == m
);
35 assert(ym
.day() == d
);
36 assert(static_cast<int>((ym
).year()) == i
+ 2);
37 assert(ym
.month() == m
);
38 assert(ym
.day() == d
);
39 assert(static_cast<int>((ym
-= years
{1}).year()) == i
+ 1);
40 assert(ym
.month() == m
);
41 assert(ym
.day() == d
);
42 assert(static_cast<int>((ym
).year()) == i
+ 1);
43 assert(ym
.month() == m
);
44 assert(ym
.day() == d
);
50 int main(int, char**) {
51 ASSERT_NOEXCEPT(std::declval
<year_month_day
&>() += std::declval
<years
>());
52 ASSERT_NOEXCEPT(std::declval
<year_month_day
&>() -= std::declval
<years
>());
54 ASSERT_SAME_TYPE(year_month_day
&, decltype(std::declval
<year_month_day
&>() += std::declval
<years
>()));
55 ASSERT_SAME_TYPE(year_month_day
&, decltype(std::declval
<year_month_day
&>() -= std::declval
<years
>()));
58 static_assert(test());