• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //   Returns: x.month() == y.month() && x.day() == y.day().
15 //
16 // constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
17 //   Returns:
18 //      If x.month() < y.month() returns true.
19 //      Otherwise, if x.month() > y.month() returns false.
20 //      Otherwise, returns x.day() < y.day().
21 
22 #include <chrono>
23 #include <type_traits>
24 #include <cassert>
25 
26 #include "test_macros.h"
27 #include "test_comparisons.h"
28 
main(int,char **)29 int main(int, char**)
30 {
31     using day       = std::chrono::day;
32     using month     = std::chrono::month;
33     using month_day = std::chrono::month_day;
34 
35     AssertComparisons6AreNoexcept<month_day>();
36     AssertComparisons6ReturnBool<month_day>();
37 
38     static_assert( testComparisons6(
39         month_day{std::chrono::January, day{1}},
40         month_day{std::chrono::January, day{1}},
41         true, false), "");
42 
43     static_assert( testComparisons6(
44         month_day{std::chrono::January, day{1}},
45         month_day{std::chrono::January, day{2}},
46         false, true), "");
47 
48     static_assert( testComparisons6(
49         month_day{std::chrono::January,  day{1}},
50         month_day{std::chrono::February, day{1}},
51         false, true), "");
52 
53 //  same day, different months
54     for (unsigned i = 1; i < 12; ++i)
55         for (unsigned j = 1; j < 12; ++j)
56             assert((testComparisons6(
57                 month_day{month{i}, day{1}},
58                 month_day{month{j}, day{1}},
59                 i == j, i < j )));
60 
61 //  same month, different days
62     for (unsigned i = 1; i < 31; ++i)
63         for (unsigned j = 1; j < 31; ++j)
64             assert((testComparisons6(
65                 month_day{month{2}, day{i}},
66                 month_day{month{2}, day{j}},
67                 i == j, i < j )));
68 
69 
70   return 0;
71 }
72