122 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <chrono>11// class year_month_day;12 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;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 year = std::chrono::year;26 using month = std::chrono::month;27 using year_month_day = std::chrono::year_month_day;28 29 constexpr month January = std::chrono::January;30 constexpr month February = std::chrono::February;31 32 assert(testOrder(33 year_month_day{year{1234}, January, day{1}},34 year_month_day{year{1234}, January, day{1}},35 std::strong_ordering::equal));36 37 // different day38 assert(testOrder(39 year_month_day{year{1234}, January, day{1}},40 year_month_day{year{1234}, January, day{2}},41 std::strong_ordering::less));42 43 // different month44 assert(testOrder(45 year_month_day{year{1234}, January, day{1}},46 year_month_day{year{1234}, February, day{1}},47 std::strong_ordering::less));48 49 // different year50 assert(testOrder(51 year_month_day{year{1234}, January, day{1}},52 year_month_day{year{1235}, January, day{1}},53 std::strong_ordering::less));54 55 // different month and day56 assert(testOrder(57 year_month_day{year{1234}, January, day{2}},58 year_month_day{year{1234}, February, day{1}},59 std::strong_ordering::less));60 61 // different year and month62 assert(testOrder(63 year_month_day{year{1234}, February, day{1}},64 year_month_day{year{1235}, January, day{1}},65 std::strong_ordering::less));66 67 // different year and day68 assert(testOrder(69 year_month_day{year{1234}, January, day{2}},70 year_month_day{year{1235}, January, day{1}},71 std::strong_ordering::less));72 73 // different year, month and day74 assert(testOrder(75 year_month_day{year{1234}, February, day{2}},76 year_month_day{year{1235}, January, day{1}},77 std::strong_ordering::less));78 79 // same year, different days80 for (unsigned i = 1; i < 28; ++i)81 for (unsigned j = 1; j < 28; ++j)82 assert((testOrder(83 year_month_day{year{1234}, January, day{i}},84 year_month_day{year{1234}, January, day{j}},85 i == j ? std::strong_ordering::equal86 : i < j ? std::strong_ordering::less87 : std::strong_ordering::greater)));88 89 // same year, different months90 for (unsigned i = 1; i < 12; ++i)91 for (unsigned j = 1; j < 12; ++j)92 assert((testOrder(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::equal96 : i < j ? std::strong_ordering::less97 : std::strong_ordering::greater)));98 99 // same month, different years100 for (int i = -5; i < 5; ++i)101 for (int j = -5; j < 5; ++j)102 assert((testOrder(103 year_month_day{year{i}, January, day{12}},104 year_month_day{year{j}, January, day{12}},105 i == j ? std::strong_ordering::equal106 : i < j ? std::strong_ordering::less107 : std::strong_ordering::greater)));108 109 return true;110}111 112int 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>();116 117 test();118 static_assert(test());119 120 return 0;121}122