1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
12 // class year_month_weekday_last;
14 // constexpr year_month_weekday_last
15 // operator/(const year_month& ym, const weekday_last& wdl) noexcept;
16 // Returns: {ym.year(), ym.month(), wdl}.
18 // constexpr year_month_weekday_last
19 // operator/(const year& y, const month_weekday_last& mwdl) noexcept;
20 // Returns: {y, mwdl.month(), mwdl.weekday_last()}.
22 // constexpr year_month_weekday_last
23 // operator/(int y, const month_weekday_last& mwdl) noexcept;
24 // Returns: year(y) / mwdl.
26 // constexpr year_month_weekday_last
27 // operator/(const month_weekday_last& mwdl, const year& y) noexcept;
30 // constexpr year_month_weekday_last
31 // operator/(const month_weekday_last& mwdl, int y) noexcept;
32 // Returns: year(y) / mwdl.
37 #include <type_traits>
40 #include "test_macros.h"
41 #include "test_comparisons.h"
45 using year_month = std::chrono::year_month;
46 using year = std::chrono::year;
47 using month = std::chrono::month;
48 using weekday = std::chrono::weekday;
49 using weekday_last = std::chrono::weekday_last;
50 using month_weekday_last = std::chrono::month_weekday_last;
51 using year_month_weekday_last = std::chrono::year_month_weekday_last;
53 constexpr weekday Tuesday = std::chrono::Tuesday;
54 constexpr month February = std::chrono::February;
56 { // operator/(const year_month& ym, const weekday_last& wdl) (and switched)
57 constexpr year_month Feb2018{year{2018}, February};
59 ASSERT_NOEXCEPT ( Feb2018/weekday_last{Tuesday});
60 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(Feb2018/weekday_last{Tuesday}));
62 static_assert((Feb2018/weekday_last{Tuesday}).year() == year{2018}, "");
63 static_assert((Feb2018/weekday_last{Tuesday}).month() == February, "");
64 static_assert((Feb2018/weekday_last{Tuesday}).weekday() == Tuesday, "");
66 for (int i = 1000; i < 1010; ++i)
67 for (unsigned j = 1; j <= 12; ++j)
68 for (unsigned k = 0; k <= 6; ++k)
73 year_month_weekday_last ymwdl = year_month{y,m}/weekday_last{wd};
74 assert(ymwdl.year() == y);
75 assert(ymwdl.month() == m);
76 assert(ymwdl.weekday() == wd);
81 { // operator/(const year& y, const month_weekday_last& mwdl) (and switched)
82 constexpr month_weekday_last FebLastTues{February, weekday_last{Tuesday}};
84 ASSERT_NOEXCEPT ( year{2018}/FebLastTues);
85 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(year{2018}/FebLastTues));
86 ASSERT_NOEXCEPT ( FebLastTues/year{2018});
87 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(FebLastTues/year{2018}));
90 static_assert((year{2018}/FebLastTues).year() == year{2018}, "");
91 static_assert((year{2018}/FebLastTues).month() == February, "");
92 static_assert((year{2018}/FebLastTues).weekday() == Tuesday, "");
93 static_assert((FebLastTues/year{2018}).year() == year{2018}, "");
94 static_assert((FebLastTues/year{2018}).month() == February, "");
95 static_assert((FebLastTues/year{2018}).weekday() == Tuesday, "");
98 for (int i = 1000; i < 1010; ++i)
99 for (unsigned j = 1; j <= 12; ++j)
100 for (unsigned k = 0; k <= 6; ++k)
105 year_month_weekday_last ymwdl1 = y/month_weekday_last{m, weekday_last{wd}};
106 year_month_weekday_last ymwdl2 = month_weekday_last{m, weekday_last{wd}}/y;
107 assert(ymwdl1.year() == y);
108 assert(ymwdl2.year() == y);
109 assert(ymwdl1.month() == m);
110 assert(ymwdl2.month() == m);
111 assert(ymwdl1.weekday() == wd);
112 assert(ymwdl2.weekday() == wd);
113 assert(ymwdl1 == ymwdl2);
118 { // operator/(int y, const month_weekday_last& mwdl) (and switched)
119 constexpr month_weekday_last FebLastTues{February, weekday_last{Tuesday}};
121 ASSERT_NOEXCEPT ( 2018/FebLastTues);
122 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(2018/FebLastTues));
123 ASSERT_NOEXCEPT ( FebLastTues/2018);
124 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(FebLastTues/2018));
127 static_assert((2018/FebLastTues).year() == year{2018}, "");
128 static_assert((2018/FebLastTues).month() == February, "");
129 static_assert((2018/FebLastTues).weekday() == Tuesday, "");
130 static_assert((FebLastTues/2018).year() == year{2018}, "");
131 static_assert((FebLastTues/2018).month() == February, "");
132 static_assert((FebLastTues/2018).weekday() == Tuesday, "");
135 for (int i = 1000; i < 1010; ++i)
136 for (unsigned j = 1; j <= 12; ++j)
137 for (unsigned k = 0; k <= 6; ++k)
142 year_month_weekday_last ymwdl1 = i/month_weekday_last{m, weekday_last{wd}};
143 year_month_weekday_last ymwdl2 = month_weekday_last{m, weekday_last{wd}}/i;
144 assert(ymwdl1.year() == y);
145 assert(ymwdl2.year() == y);
146 assert(ymwdl1.month() == m);
147 assert(ymwdl2.month() == m);
148 assert(ymwdl1.weekday() == wd);
149 assert(ymwdl2.weekday() == wd);
150 assert(ymwdl1 == ymwdl2);