• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10 
11 // <chrono>
12 // class year_month;
13 
14 // constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
15 //   Returns: x.year() == y.year() && x.month() == y.month().
16 //
17 // constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
18 //   Returns:
19 //      If x.year() < y.year() returns true.
20 //      Otherwise, if x.year() > y.year() returns false.
21 //      Otherwise, returns x.month() < y.month().
22 
23 #include <chrono>
24 #include <type_traits>
25 #include <cassert>
26 
27 #include "test_macros.h"
28 #include "test_comparisons.h"
29 
main()30 int main()
31 {
32     using year       = std::chrono::year;
33     using month      = std::chrono::month;
34     using year_month = std::chrono::year_month;
35 
36     AssertComparisons6AreNoexcept<year_month>();
37     AssertComparisons6ReturnBool<year_month>();
38 
39     static_assert( testComparisons6(
40         year_month{year{1234}, std::chrono::January},
41         year_month{year{1234}, std::chrono::January},
42         true, false), "");
43 
44     static_assert( testComparisons6(
45         year_month{year{1234}, std::chrono::January},
46         year_month{year{1234}, std::chrono::February},
47         false, true), "");
48 
49     static_assert( testComparisons6(
50         year_month{year{1234}, std::chrono::January},
51         year_month{year{1235}, std::chrono::January},
52         false, true), "");
53 
54 //  same year, different months
55     for (unsigned i = 1; i < 12; ++i)
56         for (unsigned j = 1; j < 12; ++j)
57             assert((testComparisons6(
58                 year_month{year{1234}, month{i}},
59                 year_month{year{1234}, month{j}},
60                 i == j, i < j )));
61 
62 //  same month, different years
63     for (int i = 1000; i < 20; ++i)
64         for (int j = 1000; j < 20; ++j)
65         assert((testComparisons6(
66             year_month{year{i}, std::chrono::January},
67             year_month{year{j}, std::chrono::January},
68             i == j, i < j )));
69 }
70