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// UNSUPPORTED: c++03, c++11, c++14, c++17
9
10// <chrono>
11// class month_day;
12
13// constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
14// constexpr strong_comparison operator<=>(const month_day& x, const month_day& y) noexcept;
15
16#include <chrono>
17#include <type_traits>
18#include <cassert>
19
20#include "test_macros.h"
21#include "test_comparisons.h"
22
23constexpr bool test() {
24 using day = std::chrono::day;
25 using month = std::chrono::month;
26 using month_day = std::chrono::month_day;
27
28 assert(testOrder(
29 month_day{std::chrono::January, day{1}}, month_day{std::chrono::January, day{1}}, std::strong_ordering::equal));
30
31 assert(testOrder(
32 month_day{std::chrono::January, day{1}}, month_day{std::chrono::January, day{2}}, std::strong_ordering::less));
33
34 assert(testOrder(
35 month_day{std::chrono::January, day{1}}, month_day{std::chrono::February, day{1}}, std::strong_ordering::less));
36
37 // same day, different months
38 for (unsigned i = 1; i < 12; ++i)
39 for (unsigned j = 1; j < 12; ++j)
40 assert((testOrder(
41 month_day{month{i}, day{1}},
42 month_day{month{j}, day{1}},
43 i == j ? std::strong_ordering::equal
44 : i < j ? std::strong_ordering::less
45 : std::strong_ordering::greater)));
46
47 // same month, different days
48 for (unsigned i = 1; i < 31; ++i)
49 for (unsigned j = 1; j < 31; ++j)
50 assert((testOrder(
51 month_day{month{2}, day{i}},
52 month_day{month{2}, day{j}},
53 i == j ? std::strong_ordering::equal
54 : i < j ? std::strong_ordering::less
55 : std::strong_ordering::greater)));
56
57 return true;
58}
59
60int main(int, char**) {
61 using month_day = std::chrono::month_day;
62 AssertOrderAreNoexcept<month_day>();
63 AssertOrderReturn<std::strong_ordering, month_day>();
64
65 test();
66 static_assert(test());
67
68 return 0;
69}
70

source code of libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp