1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9
10 // <chrono>
11 // class year_month_weekday_last;
12
13 // constexpr year_month_weekday_last
14 // operator/(const year_month& ym, const weekday_last& wdl) noexcept;
15 // Returns: {ym.year(), ym.month(), wdl}.
16 //
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()}.
20 //
21 // constexpr year_month_weekday_last
22 // operator/(int y, const month_weekday_last& mwdl) noexcept;
23 // Returns: year(y) / mwdl.
24 //
25 // constexpr year_month_weekday_last
26 // operator/(const month_weekday_last& mwdl, const year& y) noexcept;
27 // Returns: y / mwdl.
28 //
29 // constexpr year_month_weekday_last
30 // operator/(const month_weekday_last& mwdl, int y) noexcept;
31 // Returns: year(y) / mwdl.
32
33
34
35 #include <chrono>
36 #include <type_traits>
37 #include <cassert>
38
39 #include "test_macros.h"
40
main(int,char **)41 int main(int, char**)
42 {
43 using year_month = std::chrono::year_month;
44 using year = std::chrono::year;
45 using month = std::chrono::month;
46 using weekday = std::chrono::weekday;
47 using weekday_last = std::chrono::weekday_last;
48 using month_weekday_last = std::chrono::month_weekday_last;
49 using year_month_weekday_last = std::chrono::year_month_weekday_last;
50
51 constexpr weekday Tuesday = std::chrono::Tuesday;
52 constexpr month February = std::chrono::February;
53
54 { // operator/(const year_month& ym, const weekday_last& wdl) (and switched)
55 constexpr year_month Feb2018{year{2018}, February};
56
57 ASSERT_NOEXCEPT ( Feb2018/weekday_last{Tuesday});
58 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(Feb2018/weekday_last{Tuesday}));
59
60 static_assert((Feb2018/weekday_last{Tuesday}).year() == year{2018}, "");
61 static_assert((Feb2018/weekday_last{Tuesday}).month() == February, "");
62 static_assert((Feb2018/weekday_last{Tuesday}).weekday() == Tuesday, "");
63
64 for (int i = 1000; i < 1010; ++i)
65 for (unsigned j = 1; j <= 12; ++j)
66 for (unsigned k = 0; k <= 6; ++k)
67 {
68 year y{i};
69 month m{j};
70 weekday wd{k};
71 year_month_weekday_last ymwdl = year_month{y,m}/weekday_last{wd};
72 assert(ymwdl.year() == y);
73 assert(ymwdl.month() == m);
74 assert(ymwdl.weekday() == wd);
75 }
76 }
77
78
79 { // operator/(const year& y, const month_weekday_last& mwdl) (and switched)
80 constexpr month_weekday_last FebLastTues{February, weekday_last{Tuesday}};
81
82 ASSERT_NOEXCEPT ( year{2018}/FebLastTues);
83 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(year{2018}/FebLastTues));
84 ASSERT_NOEXCEPT ( FebLastTues/year{2018});
85 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(FebLastTues/year{2018}));
86
87
88 static_assert((year{2018}/FebLastTues).year() == year{2018}, "");
89 static_assert((year{2018}/FebLastTues).month() == February, "");
90 static_assert((year{2018}/FebLastTues).weekday() == Tuesday, "");
91 static_assert((FebLastTues/year{2018}).year() == year{2018}, "");
92 static_assert((FebLastTues/year{2018}).month() == February, "");
93 static_assert((FebLastTues/year{2018}).weekday() == Tuesday, "");
94
95
96 for (int i = 1000; i < 1010; ++i)
97 for (unsigned j = 1; j <= 12; ++j)
98 for (unsigned k = 0; k <= 6; ++k)
99 {
100 year y{i};
101 month m{j};
102 weekday wd{k};
103 year_month_weekday_last ymwdl1 = y/month_weekday_last{m, weekday_last{wd}};
104 year_month_weekday_last ymwdl2 = month_weekday_last{m, weekday_last{wd}}/y;
105 assert(ymwdl1.year() == y);
106 assert(ymwdl2.year() == y);
107 assert(ymwdl1.month() == m);
108 assert(ymwdl2.month() == m);
109 assert(ymwdl1.weekday() == wd);
110 assert(ymwdl2.weekday() == wd);
111 assert(ymwdl1 == ymwdl2);
112 }
113 }
114
115
116 { // operator/(int y, const month_weekday_last& mwdl) (and switched)
117 constexpr month_weekday_last FebLastTues{February, weekday_last{Tuesday}};
118
119 ASSERT_NOEXCEPT ( 2018/FebLastTues);
120 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(2018/FebLastTues));
121 ASSERT_NOEXCEPT ( FebLastTues/2018);
122 ASSERT_SAME_TYPE(year_month_weekday_last, decltype(FebLastTues/2018));
123
124
125 static_assert((2018/FebLastTues).year() == year{2018}, "");
126 static_assert((2018/FebLastTues).month() == February, "");
127 static_assert((2018/FebLastTues).weekday() == Tuesday, "");
128 static_assert((FebLastTues/2018).year() == year{2018}, "");
129 static_assert((FebLastTues/2018).month() == February, "");
130 static_assert((FebLastTues/2018).weekday() == Tuesday, "");
131
132
133 for (int i = 1000; i < 1010; ++i)
134 for (unsigned j = 1; j <= 12; ++j)
135 for (unsigned k = 0; k <= 6; ++k)
136 {
137 year y{i};
138 month m{j};
139 weekday wd{k};
140 year_month_weekday_last ymwdl1 = i/month_weekday_last{m, weekday_last{wd}};
141 year_month_weekday_last ymwdl2 = month_weekday_last{m, weekday_last{wd}}/i;
142 assert(ymwdl1.year() == y);
143 assert(ymwdl2.year() == y);
144 assert(ymwdl1.month() == m);
145 assert(ymwdl2.month() == m);
146 assert(ymwdl1.weekday() == wd);
147 assert(ymwdl2.weekday() == wd);
148 assert(ymwdl1 == ymwdl2);
149 }
150 }
151
152 return 0;
153 }
154