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 year_month;
12
13// constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
14// constexpr strong_order operator<=>(const year_month& x, const year_month& 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 year = std::chrono::year;
25 using month = std::chrono::month;
26 using year_month = std::chrono::year_month;
27
28 assert(testOrder(
29 year_month{year{1234}, std::chrono::January},
30 year_month{year{1234}, std::chrono::January},
31 std::strong_ordering::equal));
32
33 assert(testOrder(
34 year_month{year{1234}, std::chrono::January},
35 year_month{year{1234}, std::chrono::February},
36 std::strong_ordering::less));
37
38 assert(testOrder(
39 year_month{year{1234}, std::chrono::January},
40 year_month{year{1235}, std::chrono::January},
41 std::strong_ordering::less));
42
43 // same year, different months
44 for (unsigned i = 1; i < 12; ++i)
45 for (unsigned j = 1; j < 12; ++j)
46 assert((testOrder(
47 year_month{year{1234}, month{i}},
48 year_month{year{1234}, month{j}},
49 i == j ? std::strong_ordering::equal
50 : i < j ? std::strong_ordering::less
51 : std::strong_ordering::greater)));
52
53 // same month, different years
54 for (int i = -5; i < 5; ++i)
55 for (int j = -5; j < 5; ++j)
56 assert((testOrder(
57 year_month{year{i}, std::chrono::January},
58 year_month{year{j}, std::chrono::January},
59 i == j ? std::strong_ordering::equal
60 : i < j ? std::strong_ordering::less
61 : std::strong_ordering::greater)));
62
63 return true;
64}
65
66int main(int, char**) {
67 using year_month = std::chrono::year_month;
68 AssertOrderAreNoexcept<year_month>();
69 AssertOrderReturn<std::strong_ordering, year_month>();
70
71 test();
72 static_assert(test());
73
74 return 0;
75}
76

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