• 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 year_month;
12 
13 // constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
14 //   Returns: x.year() == y.year() && x.month() == y.month().
15 //
16 // constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
17 //   Returns:
18 //      If x.year() < y.year() returns true.
19 //      Otherwise, if x.year() > y.year() returns false.
20 //      Otherwise, returns x.month() < y.month().
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 year       = std::chrono::year;
32     using month      = std::chrono::month;
33     using year_month = std::chrono::year_month;
34 
35     AssertComparisons6AreNoexcept<year_month>();
36     AssertComparisons6ReturnBool<year_month>();
37 
38     static_assert( testComparisons6(
39         year_month{year{1234}, std::chrono::January},
40         year_month{year{1234}, std::chrono::January},
41         true, false), "");
42 
43     static_assert( testComparisons6(
44         year_month{year{1234}, std::chrono::January},
45         year_month{year{1234}, std::chrono::February},
46         false, true), "");
47 
48     static_assert( testComparisons6(
49         year_month{year{1234}, std::chrono::January},
50         year_month{year{1235}, std::chrono::January},
51         false, true), "");
52 
53 //  same year, different months
54     for (unsigned i = 1; i < 12; ++i)
55         for (unsigned j = 1; j < 12; ++j)
56             assert((testComparisons6(
57                 year_month{year{1234}, month{i}},
58                 year_month{year{1234}, month{j}},
59                 i == j, i < j )));
60 
61 //  same month, different years
62     for (int i = 1000; i < 20; ++i)
63         for (int j = 1000; j < 20; ++j)
64         assert((testComparisons6(
65             year_month{year{i}, std::chrono::January},
66             year_month{year{j}, std::chrono::January},
67             i == j, i < j )));
68 
69   return 0;
70 }
71