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_last;
13 // constexpr year_month_day_last& operator+=(const months& m) noexcept;
14 // constexpr year_month_day_last& operator-=(const months& m) noexcept;
18 #include <type_traits>
21 #include "test_macros.h"
23 using year
= std::chrono::year
;
24 using month
= std::chrono::month
;
25 using month_day_last
= std::chrono::month_day_last
;
26 using year_month_day_last
= std::chrono::year_month_day_last
;
27 using months
= std::chrono::months
;
29 constexpr bool test() {
30 for (unsigned i
= 0; i
<= 10; ++i
) {
32 month_day_last mdl
{month
{i
}};
33 year_month_day_last
ymdl(y
, mdl
);
34 assert(static_cast<unsigned>((ymdl
+= months
{2}).month()) == i
+ 2);
35 assert(ymdl
.year() == y
);
36 assert(static_cast<unsigned>((ymdl
).month()) == i
+ 2);
37 assert(ymdl
.year() == y
);
38 assert(static_cast<unsigned>((ymdl
-= months
{1}).month()) == i
+ 1);
39 assert(ymdl
.year() == y
);
40 assert(static_cast<unsigned>((ymdl
).month()) == i
+ 1);
41 assert(ymdl
.year() == y
);
44 { // Test year wrapping
45 year_month_day_last ymdl
{year
{2020}, month_day_last
{month
{4}}};
48 assert((ymdl
== year_month_day_last
{year
{2021}, month_day_last
{month
{4}}}));
51 assert((ymdl
== year_month_day_last
{year
{2020}, month_day_last
{month
{4}}}));
57 int main(int, char**) {
58 ASSERT_NOEXCEPT(std::declval
<year_month_day_last
&>() += std::declval
<months
>());
59 ASSERT_NOEXCEPT(std::declval
<year_month_day_last
&>() -= std::declval
<months
>());
61 ASSERT_SAME_TYPE(year_month_day_last
&, decltype(std::declval
<year_month_day_last
&>() += std::declval
<months
>()));
62 ASSERT_SAME_TYPE(year_month_day_last
&, decltype(std::declval
<year_month_day_last
&>() -= std::declval
<months
>()));
65 static_assert(test());