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
10 // class year_month_day_last;
12 // constexpr year_month_day_last
13 // operator/(const year_month& ym, last_spec) noexcept;
14 // Returns: {ym.year(), month_day_last{ym.month()}}.
17 // constexpr year_month_day_last
18 // operator/(const year& y, const month_day_last& mdl) noexcept;
21 // constexpr year_month_day_last
22 // operator/(int y, const month_day_last& mdl) noexcept;
23 // Returns: year(y) / mdl.
25 // constexpr year_month_day_last
26 // operator/(const month_day_last& mdl, const year& y) noexcept;
29 // constexpr year_month_day_last
30 // operator/(const month_day_last& mdl, int y) noexcept;
31 // Returns: year(y) / mdl.
34 #include <type_traits>
37 #include "test_macros.h"
41 using day
= std::chrono::day
;
42 using month
= std::chrono::month
;
43 using year_month
= std::chrono::year_month
;
44 using year
= std::chrono::year
;
45 using month_day_last
= std::chrono::month_day_last
;
46 using year_month_day_last
= std::chrono::year_month_day_last
;
48 constexpr month February
= std::chrono::February
;
49 constexpr std::chrono::last_spec last
= std::chrono::last
;
51 { // operator/(const year_month& ym, last_spec)
52 constexpr year_month Feb2018
{year
{2018}, February
};
54 ASSERT_NOEXCEPT ( Feb2018
/last
);
55 ASSERT_SAME_TYPE(year_month_day_last
, decltype(Feb2018
/last
));
57 static_assert((Feb2018
/last
).year() == year
{2018}, "");
58 static_assert((Feb2018
/last
).month() == February
, "");
60 for (int i
= 1000; i
< 1010; ++i
)
61 for (unsigned j
= 1; j
<= 12; ++j
)
65 year_month_day_last ymdl
= year_month
{y
,m
}/last
;
66 assert(ymdl
.year() == y
);
67 assert(ymdl
.month() == m
);
72 { // operator/(const year& y, const month_day_last& mdl) (and switched)
73 ASSERT_NOEXCEPT ( year
{2018}/month_day_last
{February
});
74 ASSERT_SAME_TYPE(year_month_day_last
, decltype(year
{2018}/month_day_last
{February
}));
75 ASSERT_NOEXCEPT ( month_day_last
{February
}/year
{2018});
76 ASSERT_SAME_TYPE(year_month_day_last
, decltype(month_day_last
{February
}/year
{2018}));
78 static_assert((year
{2018}/month_day_last
{February
}).month() == February
, "");
79 static_assert((year
{2018}/month_day_last
{February
}).year() == year
{2018}, "");
80 static_assert((month_day_last
{February
}/year
{2018}).month() == February
, "");
81 static_assert((month_day_last
{February
}/year
{2018}).year() == year
{2018}, "");
83 for (int i
= 1000; i
< 1010; ++i
)
84 for (unsigned j
= 1; j
<= 12; ++j
)
88 year_month_day_last ymdl1
= y
/month_day_last
{m
};
89 year_month_day_last ymdl2
= month_day_last
{m
}/y
;
90 assert(ymdl1
.month() == m
);
91 assert(ymdl2
.month() == m
);
92 assert(ymdl2
.year() == y
);
93 assert(ymdl1
.year() == y
);
94 assert(ymdl1
== ymdl2
);
98 { // operator/(int y, const month_day_last& mdl) (and switched)
99 ASSERT_NOEXCEPT ( 2018/month_day_last
{February
});
100 ASSERT_SAME_TYPE(year_month_day_last
, decltype(2018/month_day_last
{February
}));
101 ASSERT_NOEXCEPT ( month_day_last
{February
}/2018);
102 ASSERT_SAME_TYPE(year_month_day_last
, decltype(month_day_last
{February
}/2018));
104 static_assert((2018/month_day_last
{February
}).month() == February
, "");
105 static_assert((2018/month_day_last
{February
}).year() == year
{2018}, "");
106 static_assert((month_day_last
{February
}/2018).month() == February
, "");
107 static_assert((month_day_last
{February
}/2018).year() == year
{2018}, "");
109 for (int i
= 1000; i
< 1010; ++i
)
110 for (unsigned j
= 1; j
<= 12; ++j
)
114 year_month_day_last ymdl1
= i
/month_day_last
{m
};
115 year_month_day_last ymdl2
= month_day_last
{m
}/i
;
116 assert(ymdl1
.month() == m
);
117 assert(ymdl2
.month() == m
);
118 assert(ymdl2
.year() == y
);
119 assert(ymdl1
.year() == y
);
120 assert(ymdl1
== ymdl2
);
124 // the result of year_month_day_last::day() is unspecified when !ok(),
125 // but it shouldn't crash.
127 year_month_day_last ymdl
= year
{2020}/month
{13}/last
;
129 day d
= ymdl
.day(); (void)d
; // doesn't crash