| 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 |
|
| 9 |
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 |
| 10 |
|
| 11 |
// <chrono> |
| 12 |
// class year_month_day_last; |
| 13 |
|
| 14 |
// constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept; |
| 15 |
// constexpr bool operator<=>(const year_month_day_last& x, const year_month_day_last& y) noexcept; |
| 16 |
|
| 17 |
#include <chrono> |
| 18 |
#include <type_traits> |
| 19 |
#include <cassert> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
#include "test_comparisons.h" |
| 23 |
|
| 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; |
| 81 |
} |