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 bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
14 // constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
17 #include <type_traits>
20 #include "test_macros.h"
21 #include "test_comparisons.h"
23 constexpr bool test() {
24 using day
= std::chrono::day
;
25 using year
= std::chrono::year
;
26 using month
= std::chrono::month
;
27 using year_month_day
= std::chrono::year_month_day
;
29 constexpr month January
= std::chrono::January
;
30 constexpr month February
= std::chrono::February
;
33 year_month_day
{year
{1234}, January
, day
{1}},
34 year_month_day
{year
{1234}, January
, day
{1}},
35 std::strong_ordering::equal
));
39 year_month_day
{year
{1234}, January
, day
{1}},
40 year_month_day
{year
{1234}, January
, day
{2}},
41 std::strong_ordering::less
));
45 year_month_day
{year
{1234}, January
, day
{1}},
46 year_month_day
{year
{1234}, February
, day
{1}},
47 std::strong_ordering::less
));
51 year_month_day
{year
{1234}, January
, day
{1}},
52 year_month_day
{year
{1235}, January
, day
{1}},
53 std::strong_ordering::less
));
55 // different month and day
57 year_month_day
{year
{1234}, January
, day
{2}},
58 year_month_day
{year
{1234}, February
, day
{1}},
59 std::strong_ordering::less
));
61 // different year and month
63 year_month_day
{year
{1234}, February
, day
{1}},
64 year_month_day
{year
{1235}, January
, day
{1}},
65 std::strong_ordering::less
));
67 // different year and day
69 year_month_day
{year
{1234}, January
, day
{2}},
70 year_month_day
{year
{1235}, January
, day
{1}},
71 std::strong_ordering::less
));
73 // different year, month and day
75 year_month_day
{year
{1234}, February
, day
{2}},
76 year_month_day
{year
{1235}, January
, day
{1}},
77 std::strong_ordering::less
));
79 // same year, different days
80 for (unsigned i
= 1; i
< 28; ++i
)
81 for (unsigned j
= 1; j
< 28; ++j
)
83 year_month_day
{year
{1234}, January
, day
{i
}},
84 year_month_day
{year
{1234}, January
, day
{j
}},
85 i
== j
? std::strong_ordering::equal
86 : i
< j
? std::strong_ordering::less
87 : std::strong_ordering::greater
)));
89 // same year, different months
90 for (unsigned i
= 1; i
< 12; ++i
)
91 for (unsigned j
= 1; j
< 12; ++j
)
93 year_month_day
{year
{1234}, month
{i
}, day
{12}},
94 year_month_day
{year
{1234}, month
{j
}, day
{12}},
95 i
== j
? std::strong_ordering::equal
96 : i
< j
? std::strong_ordering::less
97 : std::strong_ordering::greater
)));
99 // same month, different years
100 for (int i
= -5; i
< 5; ++i
)
101 for (int j
= -5; j
< 5; ++j
)
103 year_month_day
{year
{i
}, January
, day
{12}},
104 year_month_day
{year
{j
}, January
, day
{12}},
105 i
== j
? std::strong_ordering::equal
106 : i
< j
? std::strong_ordering::less
107 : std::strong_ordering::greater
)));
112 int main(int, char**) {
113 using year_month_day
= std::chrono::year_month_day
;
114 AssertOrderAreNoexcept
<year_month_day
>();
115 AssertOrderReturn
<std::strong_ordering
, year_month_day
>();
118 static_assert(test());