|
5 | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 |
| -// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 8 | + |
| 9 | +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 |
9 | 10 |
|
10 | 11 | // <chrono>
|
11 | 12 | // class year_month_day_last;
|
12 | 13 |
|
13 | 14 | // constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
|
14 |
| -// Returns: x.year() == y.year() && x.month_day_last() == y.month_day_last(). |
15 |
| -// |
16 |
| -// constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept; |
17 |
| -// Returns: |
18 |
| -// If x.year() < y.year(), returns true. |
19 |
| -// Otherwise, if x.year() > y.year(), returns false. |
20 |
| -// Otherwise, returns x.month_day_last() < y.month_day_last() |
| 15 | +// constexpr bool operator<=>(const year_month_day_last& x, const year_month_day_last& y) noexcept; |
21 | 16 |
|
22 | 17 | #include <chrono>
|
23 | 18 | #include <type_traits>
|
|
26 | 21 | #include "test_macros.h"
|
27 | 22 | #include "test_comparisons.h"
|
28 | 23 |
|
29 |
| -int main(int, char**) |
30 |
| -{ |
31 |
| - using year = std::chrono::year; |
32 |
| - using month = std::chrono::month; |
33 |
| - using month_day_last = std::chrono::month_day_last; |
34 |
| - using year_month_day_last = std::chrono::year_month_day_last; |
35 |
| - |
36 |
| - AssertComparisonsAreNoexcept<year_month_day_last>(); |
37 |
| - AssertComparisonsReturnBool<year_month_day_last>(); |
38 |
| - |
39 |
| - constexpr month January = std::chrono::January; |
40 |
| - constexpr month February = std::chrono::February; |
41 |
| - |
42 |
| - static_assert( testComparisons( |
43 |
| - year_month_day_last{year{1234}, month_day_last{January}}, |
44 |
| - year_month_day_last{year{1234}, month_day_last{January}}, |
45 |
| - true, false), ""); |
46 |
| - |
47 |
| - // different month |
48 |
| - static_assert( testComparisons( |
49 |
| - year_month_day_last{year{1234}, month_day_last{January}}, |
50 |
| - year_month_day_last{year{1234}, month_day_last{February}}, |
51 |
| - false, true), ""); |
52 |
| - |
53 |
| - // different year |
54 |
| - static_assert( testComparisons( |
55 |
| - year_month_day_last{year{1234}, month_day_last{January}}, |
56 |
| - year_month_day_last{year{1235}, month_day_last{January}}, |
57 |
| - false, true), ""); |
58 |
| - |
59 |
| - // different month |
60 |
| - static_assert( testComparisons( |
61 |
| - year_month_day_last{year{1234}, month_day_last{January}}, |
62 |
| - year_month_day_last{year{1234}, month_day_last{February}}, |
63 |
| - false, true), ""); |
64 |
| - |
65 |
| - // different year and month |
66 |
| - static_assert( testComparisons( |
67 |
| - year_month_day_last{year{1234}, month_day_last{February}}, |
68 |
| - year_month_day_last{year{1235}, month_day_last{January}}, |
69 |
| - false, true), ""); |
70 |
| - |
71 |
| - // same year, different months |
72 |
| - for (unsigned i = 1; i < 12; ++i) |
73 |
| - for (unsigned j = 1; j < 12; ++j) |
74 |
| - assert((testComparisons( |
75 |
| - year_month_day_last{year{1234}, month_day_last{month{i}}}, |
76 |
| - year_month_day_last{year{1234}, month_day_last{month{j}}}, |
77 |
| - i == j, i < j ))); |
78 |
| - |
79 |
| - // same month, different years |
80 |
| - for (int i = 1000; i < 2000; ++i) |
81 |
| - for (int j = 1000; j < 2000; ++j) |
82 |
| - assert((testComparisons( |
83 |
| - year_month_day_last{year{i}, month_day_last{January}}, |
84 |
| - year_month_day_last{year{j}, month_day_last{January}}, |
85 |
| - i == j, i < j ))); |
86 |
| - |
87 |
| - return 0; |
| 24 | +constexpr bool test() { |
| 25 | + using year = std::chrono::year; |
| 26 | + using month = std::chrono::month; |
| 27 | + using month_day_last = std::chrono::month_day_last; |
| 28 | + using year_month_day_last = std::chrono::year_month_day_last; |
| 29 | + |
| 30 | + constexpr month January = std::chrono::January; |
| 31 | + constexpr month February = std::chrono::February; |
| 32 | + |
| 33 | + assert(testOrder(year_month_day_last{year{1234}, month_day_last{January}}, |
| 34 | + year_month_day_last{year{1234}, month_day_last{January}}, |
| 35 | + std::strong_ordering::equal)); |
| 36 | + |
| 37 | + // different month |
| 38 | + assert(testOrder(year_month_day_last{year{1234}, month_day_last{January}}, |
| 39 | + year_month_day_last{year{1234}, month_day_last{February}}, |
| 40 | + std::strong_ordering::less)); |
| 41 | + |
| 42 | + // different year |
| 43 | + assert(testOrder(year_month_day_last{year{1234}, month_day_last{January}}, |
| 44 | + year_month_day_last{year{1235}, month_day_last{January}}, |
| 45 | + std::strong_ordering::less)); |
| 46 | + |
| 47 | + // different year and month |
| 48 | + assert(testOrder(year_month_day_last{year{1234}, month_day_last{February}}, |
| 49 | + year_month_day_last{year{1235}, month_day_last{January}}, |
| 50 | + std::strong_ordering::less)); |
| 51 | + |
| 52 | + // same year, different months |
| 53 | + for (unsigned i = 1; i < 12; ++i) |
| 54 | + for (unsigned j = 1; j < 12; ++j) |
| 55 | + assert((testOrder(year_month_day_last{year{1234}, month_day_last{month{i}}}, |
| 56 | + year_month_day_last{year{1234}, month_day_last{month{j}}}, |
| 57 | + i == j ? std::strong_ordering::equal |
| 58 | + : i < j ? std::strong_ordering::less |
| 59 | + : std::strong_ordering::greater))); |
| 60 | + |
| 61 | + // same month, different years |
| 62 | + for (int i = 1000; i < 20; ++i) |
| 63 | + for (int j = 1000; j < 20; ++j) |
| 64 | + assert((testOrder(year_month_day_last{year{i}, month_day_last{January}}, |
| 65 | + year_month_day_last{year{j}, month_day_last{January}}, |
| 66 | + i == j ? std::strong_ordering::equal |
| 67 | + : i < j ? std::strong_ordering::less |
| 68 | + : std::strong_ordering::greater))); |
| 69 | + return true; |
| 70 | +} |
| 71 | + |
| 72 | +int main(int, char**) { |
| 73 | + using year_month_day_last = std::chrono::year_month_day_last; |
| 74 | + AssertOrderAreNoexcept<year_month_day_last>(); |
| 75 | + AssertOrderReturn<std::strong_ordering, year_month_day_last>(); |
| 76 | + |
| 77 | + test(); |
| 78 | + static_assert(test()); |
| 79 | + |
| 80 | + return 0; |
88 | 81 | }
|
0 commit comments