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_last;
13 // constexpr year_month_weekday_last
14 // operator/(const year_month& ym, const weekday_last& wdl) noexcept;
15 // Returns: {ym.year(), ym.month(), wdl}.
17 // constexpr year_month_weekday_last
18 // operator/(const year& y, const month_weekday_last& mwdl) noexcept;
19 // Returns: {y, mwdl.month(), mwdl.weekday_last()}.
21 // constexpr year_month_weekday_last
22 // operator/(int y, const month_weekday_last& mwdl) noexcept;
23 // Returns: year(y) / mwdl.
25 // constexpr year_month_weekday_last
26 // operator/(const month_weekday_last& mwdl, const year& y) noexcept;
29 // constexpr year_month_weekday_last
30 // operator/(const month_weekday_last& mwdl, int y) noexcept;
31 // Returns: year(y) / mwdl.
34 #include <type_traits>
37 #include "test_macros.h"
41 using year_month
= std::chrono::year_month
;
42 using year
= std::chrono::year
;
43 using month
= std::chrono::month
;
44 using weekday
= std::chrono::weekday
;
45 using weekday_last
= std::chrono::weekday_last
;
46 using month_weekday_last
= std::chrono::month_weekday_last
;
47 using year_month_weekday_last
= std::chrono::year_month_weekday_last
;
49 constexpr weekday Tuesday
= std::chrono::Tuesday
;
50 constexpr month February
= std::chrono::February
;
52 { // operator/(const year_month& ym, const weekday_last& wdl) (and switched)
53 constexpr year_month Feb2018
{year
{2018}, February
};
55 ASSERT_NOEXCEPT ( Feb2018
/weekday_last
{Tuesday
});
56 ASSERT_SAME_TYPE(year_month_weekday_last
, decltype(Feb2018
/weekday_last
{Tuesday
}));
58 static_assert((Feb2018
/weekday_last
{Tuesday
}).year() == year
{2018}, "");
59 static_assert((Feb2018
/weekday_last
{Tuesday
}).month() == February
, "");
60 static_assert((Feb2018
/weekday_last
{Tuesday
}).weekday() == Tuesday
, "");
62 for (int i
= 1000; i
< 1010; ++i
)
63 for (unsigned j
= 1; j
<= 12; ++j
)
64 for (unsigned k
= 0; k
<= 6; ++k
)
69 year_month_weekday_last ymwdl
= year_month
{y
,m
}/weekday_last
{wd
};
70 assert(ymwdl
.year() == y
);
71 assert(ymwdl
.month() == m
);
72 assert(ymwdl
.weekday() == wd
);
77 { // operator/(const year& y, const month_weekday_last& mwdl) (and switched)
78 constexpr month_weekday_last FebLastTues
{February
, weekday_last
{Tuesday
}};
80 ASSERT_NOEXCEPT ( year
{2018}/FebLastTues
);
81 ASSERT_SAME_TYPE(year_month_weekday_last
, decltype(year
{2018}/FebLastTues
));
82 ASSERT_NOEXCEPT ( FebLastTues
/year
{2018});
83 ASSERT_SAME_TYPE(year_month_weekday_last
, decltype(FebLastTues
/year
{2018}));
86 static_assert((year
{2018}/FebLastTues
).year() == year
{2018}, "");
87 static_assert((year
{2018}/FebLastTues
).month() == February
, "");
88 static_assert((year
{2018}/FebLastTues
).weekday() == Tuesday
, "");
89 static_assert((FebLastTues
/year
{2018}).year() == year
{2018}, "");
90 static_assert((FebLastTues
/year
{2018}).month() == February
, "");
91 static_assert((FebLastTues
/year
{2018}).weekday() == Tuesday
, "");
94 for (int i
= 1000; i
< 1010; ++i
)
95 for (unsigned j
= 1; j
<= 12; ++j
)
96 for (unsigned k
= 0; k
<= 6; ++k
)
101 year_month_weekday_last ymwdl1
= y
/month_weekday_last
{m
, weekday_last
{wd
}};
102 year_month_weekday_last ymwdl2
= month_weekday_last
{m
, weekday_last
{wd
}}/y
;
103 assert(ymwdl1
.year() == y
);
104 assert(ymwdl2
.year() == y
);
105 assert(ymwdl1
.month() == m
);
106 assert(ymwdl2
.month() == m
);
107 assert(ymwdl1
.weekday() == wd
);
108 assert(ymwdl2
.weekday() == wd
);
109 assert(ymwdl1
== ymwdl2
);
114 { // operator/(int y, const month_weekday_last& mwdl) (and switched)
115 constexpr month_weekday_last FebLastTues
{February
, weekday_last
{Tuesday
}};
117 ASSERT_NOEXCEPT ( 2018/FebLastTues
);
118 ASSERT_SAME_TYPE(year_month_weekday_last
, decltype(2018/FebLastTues
));
119 ASSERT_NOEXCEPT ( FebLastTues
/2018);
120 ASSERT_SAME_TYPE(year_month_weekday_last
, decltype(FebLastTues
/2018));
123 static_assert((2018/FebLastTues
).year() == year
{2018}, "");
124 static_assert((2018/FebLastTues
).month() == February
, "");
125 static_assert((2018/FebLastTues
).weekday() == Tuesday
, "");
126 static_assert((FebLastTues
/2018).year() == year
{2018}, "");
127 static_assert((FebLastTues
/2018).month() == February
, "");
128 static_assert((FebLastTues
/2018).weekday() == Tuesday
, "");
131 for (int i
= 1000; i
< 1010; ++i
)
132 for (unsigned j
= 1; j
<= 12; ++j
)
133 for (unsigned k
= 0; k
<= 6; ++k
)
138 year_month_weekday_last ymwdl1
= i
/month_weekday_last
{m
, weekday_last
{wd
}};
139 year_month_weekday_last ymwdl2
= month_weekday_last
{m
, weekday_last
{wd
}}/i
;
140 assert(ymwdl1
.year() == y
);
141 assert(ymwdl2
.year() == y
);
142 assert(ymwdl1
.month() == m
);
143 assert(ymwdl2
.month() == m
);
144 assert(ymwdl1
.weekday() == wd
);
145 assert(ymwdl2
.weekday() == wd
);
146 assert(ymwdl1
== ymwdl2
);