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_weekday;
13 // constexpr year_month_weekday operator+(const year_month_weekday& ymd, const months& dm) noexcept;
14 // Returns: (ymd.year() / ymd.month() + dm) / ymd.day().
16 // constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymd) noexcept;
20 // constexpr year_month_weekday operator+(const year_month_weekday& ymd, const years& dy) noexcept;
21 // Returns: (ymd.year() + dy) / ymd.month() / ymd.day().
23 // constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymd) noexcept;
28 #include <type_traits>
31 #include "test_macros.h"
33 using year
= std::chrono::year
;
34 using month
= std::chrono::month
;
35 using weekday
= std::chrono::weekday
;
36 using weekday_indexed
= std::chrono::weekday_indexed
;
37 using year_month_weekday
= std::chrono::year_month_weekday
;
38 using years
= std::chrono::years
;
39 using months
= std::chrono::months
;
41 constexpr bool test() {
42 constexpr weekday Tuesday
= std::chrono::Tuesday
;
43 constexpr month January
= std::chrono::January
;
45 { // year_month_weekday + months (and switched)
46 year_month_weekday ym
{year
{1234}, January
, weekday_indexed
{Tuesday
, 3}};
47 for (int i
= 0; i
<= 10; ++i
) {
48 year_month_weekday ymwd1
= ym
+ months
{i
};
49 year_month_weekday ymwd2
= months
{i
} + ym
;
50 assert(static_cast<int>(ymwd1
.year()) == 1234);
51 assert(static_cast<int>(ymwd2
.year()) == 1234);
52 assert(ymwd1
.month() == month(1 + i
));
53 assert(ymwd2
.month() == month(1 + i
));
54 assert(ymwd1
.weekday() == Tuesday
);
55 assert(ymwd2
.weekday() == Tuesday
);
56 assert(ymwd1
.index() == 3);
57 assert(ymwd2
.index() == 3);
58 assert(ymwd1
== ymwd2
);
60 // Test the year wraps around.
61 for (int i
= 12; i
<= 15; ++i
) {
62 year_month_weekday ymwd1
= ym
+ months
{i
};
63 year_month_weekday ymwd2
= months
{i
} + ym
;
64 assert(static_cast<int>(ymwd1
.year()) == 1235);
65 assert(static_cast<int>(ymwd2
.year()) == 1235);
66 assert(ymwd1
.month() == month(1 + i
- 12));
67 assert(ymwd2
.month() == month(1 + i
- 12));
68 assert(ymwd1
.weekday() == Tuesday
);
69 assert(ymwd2
.weekday() == Tuesday
);
70 assert(ymwd1
.index() == 3);
71 assert(ymwd2
.index() == 3);
72 assert(ymwd1
== ymwd2
);
76 { // year_month_weekday + years (and switched)
77 year_month_weekday ym
{year
{1234}, std::chrono::January
, weekday_indexed
{Tuesday
, 3}};
78 for (int i
= 0; i
<= 10; ++i
) {
79 year_month_weekday ymwd1
= ym
+ years
{i
};
80 year_month_weekday ymwd2
= years
{i
} + ym
;
81 assert(static_cast<int>(ymwd1
.year()) == i
+ 1234);
82 assert(static_cast<int>(ymwd2
.year()) == i
+ 1234);
83 assert(ymwd1
.month() == January
);
84 assert(ymwd2
.month() == January
);
85 assert(ymwd1
.weekday() == Tuesday
);
86 assert(ymwd2
.weekday() == Tuesday
);
87 assert(ymwd1
.index() == 3);
88 assert(ymwd2
.index() == 3);
89 assert(ymwd1
== ymwd2
);
96 int main(int, char**) {
97 // year_month_weekday + months (and switched)
98 ASSERT_NOEXCEPT(std::declval
<year_month_weekday
>() + std::declval
<months
>());
99 ASSERT_NOEXCEPT(std::declval
<months
>() + std::declval
<year_month_weekday
>());
101 ASSERT_SAME_TYPE(year_month_weekday
, decltype(std::declval
<year_month_weekday
>() + std::declval
<months
>()));
102 ASSERT_SAME_TYPE(year_month_weekday
, decltype(std::declval
<months
>() + std::declval
<year_month_weekday
>()));
104 // year_month_weekday + years (and switched)
105 ASSERT_NOEXCEPT(std::declval
<year_month_weekday
>() + std::declval
<years
>());
106 ASSERT_NOEXCEPT(std::declval
<years
>() + std::declval
<year_month_weekday
>());
108 ASSERT_SAME_TYPE(year_month_weekday
, decltype(std::declval
<year_month_weekday
>() + std::declval
<years
>()));
109 ASSERT_SAME_TYPE(year_month_weekday
, decltype(std::declval
<years
>() + std::declval
<year_month_weekday
>()));
112 static_assert(test());