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;
13 // constexpr year_month_day
14 // operator/(const year_month& ym, const day& d) noexcept;
15 // Returns: {ym.year(), ym.month(), d}.
17 // constexpr year_month_day
18 // operator/(const year_month& ym, int d) noexcept;
19 // Returns: ym / day(d).
21 // constexpr year_month_day
22 // operator/(const year& y, const month_day& md) noexcept;
23 // Returns: y / md.month() / md.day().
25 // constexpr year_month_day
26 // operator/(int y, const month_day& md) noexcept;
27 // Returns: year(y) / md.
29 // constexpr year_month_day
30 // operator/(const month_day& md, const year& y) noexcept;
33 // constexpr year_month_day
34 // operator/(const month_day& md, int y) noexcept;
35 // Returns: year(y) / md.
38 #include <type_traits>
41 #include "test_macros.h"
45 using year
= std::chrono::year
;
46 using month
= std::chrono::month
;
47 using day
= std::chrono::day
;
48 using year_month
= std::chrono::year_month
;
49 using month_day
= std::chrono::month_day
;
50 using year_month_day
= std::chrono::year_month_day
;
52 constexpr month February
= std::chrono::February
;
53 constexpr year_month Feb2018
{year
{2018}, February
};
55 { // operator/(const year_month& ym, const day& d)
56 ASSERT_NOEXCEPT ( Feb2018
/day
{2});
57 ASSERT_SAME_TYPE(year_month_day
, decltype(Feb2018
/day
{2}));
59 static_assert((Feb2018
/day
{2}).month() == February
, "");
60 static_assert((Feb2018
/day
{2}).day() == day
{2}, "");
62 for (int i
= 1000; i
< 1010; ++i
)
63 for (int j
= 1; j
<= 12; ++j
)
64 for (unsigned k
= 0; k
<= 28; ++k
)
70 year_month_day ymd
= ym
/d
;
71 assert(ymd
.year() == y
);
72 assert(ymd
.month() == m
);
73 assert(ymd
.day() == d
);
78 { // operator/(const year_month& ym, int d)
79 ASSERT_NOEXCEPT ( Feb2018
/2);
80 ASSERT_SAME_TYPE(year_month_day
, decltype(Feb2018
/2));
82 static_assert((Feb2018
/2).month() == February
, "");
83 static_assert((Feb2018
/2).day() == day
{2}, "");
85 for (int i
= 1000; i
< 1010; ++i
)
86 for (int j
= 1; j
<= 12; ++j
)
87 for (unsigned k
= 0; k
<= 28; ++k
)
93 year_month_day ymd
= ym
/k
;
94 assert(ymd
.year() == y
);
95 assert(ymd
.month() == m
);
96 assert(ymd
.day() == d
);
101 { // operator/(const year_month& ym, int d)
102 ASSERT_NOEXCEPT ( Feb2018
/2);
103 ASSERT_SAME_TYPE(year_month_day
, decltype(Feb2018
/2));
105 static_assert((Feb2018
/2).month() == February
, "");
106 static_assert((Feb2018
/2).day() == day
{2}, "");
108 for (int i
= 1000; i
< 1010; ++i
)
109 for (int j
= 1; j
<= 12; ++j
)
110 for (unsigned k
= 0; k
<= 28; ++k
)
116 year_month_day ymd
= ym
/k
;
117 assert(ymd
.year() == y
);
118 assert(ymd
.month() == m
);
119 assert(ymd
.day() == d
);
126 { // operator/(const year& y, const month_day& md) (and switched)
127 ASSERT_NOEXCEPT ( year
{2018}/month_day
{February
, day
{2}});
128 ASSERT_SAME_TYPE(year_month_day
, decltype(year
{2018}/month_day
{February
, day
{2}}));
129 ASSERT_NOEXCEPT ( month_day
{February
, day
{2}}/year
{2018});
130 ASSERT_SAME_TYPE(year_month_day
, decltype(month_day
{February
, day
{2}}/year
{2018}));
132 static_assert((year
{2018}/month_day
{February
, day
{2}}).month() == February
, "" );
133 static_assert((year
{2018}/month_day
{February
, day
{2}}).day() == day
{2}, "" );
134 static_assert((month_day
{February
, day
{2}}/year
{2018}).month() == February
, "" );
135 static_assert((month_day
{February
, day
{2}}/year
{2018}).day() == day
{2}, "" );
137 for (int i
= 1000; i
< 1010; ++i
)
138 for (int j
= 1; j
<= 12; ++j
)
139 for (unsigned k
= 0; k
<= 28; ++k
)
145 year_month_day ymd1
= y
/md
;
146 year_month_day ymd2
= md
/y
;
147 assert(ymd1
.year() == y
);
148 assert(ymd2
.year() == y
);
149 assert(ymd1
.month() == m
);
150 assert(ymd2
.month() == m
);
151 assert(ymd1
.day() == d
);
152 assert(ymd2
.day() == d
);
153 assert(ymd1
== ymd2
);
157 { // operator/(const month_day& md, int y) (and switched)
158 ASSERT_NOEXCEPT ( 2018/month_day
{February
, day
{2}});
159 ASSERT_SAME_TYPE(year_month_day
, decltype(2018/month_day
{February
, day
{2}}));
160 ASSERT_NOEXCEPT ( month_day
{February
, day
{2}}/2018);
161 ASSERT_SAME_TYPE(year_month_day
, decltype(month_day
{February
, day
{2}}/2018));
163 static_assert((2018/month_day
{February
, day
{2}}).month() == February
, "" );
164 static_assert((2018/month_day
{February
, day
{2}}).day() == day
{2}, "" );
165 static_assert((month_day
{February
, day
{2}}/2018).month() == February
, "" );
166 static_assert((month_day
{February
, day
{2}}/2018).day() == day
{2}, "" );
168 for (int i
= 1000; i
< 1010; ++i
)
169 for (int j
= 1; j
<= 12; ++j
)
170 for (unsigned k
= 0; k
<= 28; ++k
)
176 year_month_day ymd1
= i
/md
;
177 year_month_day ymd2
= md
/i
;
178 assert(ymd1
.year() == y
);
179 assert(ymd2
.year() == y
);
180 assert(ymd1
.month() == m
);
181 assert(ymd2
.month() == m
);
182 assert(ymd1
.day() == d
);
183 assert(ymd2
.day() == d
);
184 assert(ymd1
== ymd2
);