• 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 year_month operator/(const year& y, const month& m) noexcept;
15 //   Returns: {y, m}.
16 //
17 // constexpr year_month operator/(const year& y, int m) noexcept;
18 //   Returns: y / month(m).
19 
20 
21 
22 #include <chrono>
23 #include <type_traits>
24 #include <cassert>
25 
26 #include "test_macros.h"
27 #include "test_comparisons.h"
28 
main()29 int main()
30 {
31     using month      = std::chrono::month;
32     using year       = std::chrono::year;
33     using year_month = std::chrono::year_month;
34 
35     constexpr month February = std::chrono::February;
36 
37     { // operator/(const year& y, const month& m)
38         ASSERT_NOEXCEPT (                     year{2018}/February);
39         ASSERT_SAME_TYPE(year_month, decltype(year{2018}/February));
40 
41         static_assert((year{2018}/February).year()  == year{2018}, "");
42         static_assert((year{2018}/February).month() == month{2},   "");
43         for (int i = 1000; i <= 1030; ++i)
44             for (unsigned j = 1; j <= 12; ++j)
45             {
46                 year_month ym = year{i}/month{j};
47                 assert(static_cast<int>(ym.year())       == i);
48                 assert(static_cast<unsigned>(ym.month()) == j);
49             }
50     }
51 
52 
53     { // operator/(const year& y, const int m)
54         ASSERT_NOEXCEPT (                     year{2018}/4);
55         ASSERT_SAME_TYPE(year_month, decltype(year{2018}/4));
56 
57         static_assert((year{2018}/2).year()  == year{2018}, "");
58         static_assert((year{2018}/2).month() == month{2},   "");
59 
60         for (int i = 1000; i <= 1030; ++i)
61             for (unsigned j = 1; j <= 12; ++j)
62             {
63                 year_month ym = year{i}/j;
64                 assert(static_cast<int>(ym.year())       == i);
65                 assert(static_cast<unsigned>(ym.month()) == j);
66             }
67     }
68 }
69