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 month_day
14 //   operator/(const month& m, const day& d) noexcept;
15 // Returns: {m, d}.
16 //
17 // constexpr month_day
18 //   operator/(const day& d, const month& m) noexcept;
19 // Returns: m / d.
20 
21 // constexpr month_day
22 //   operator/(const month& m, int d) noexcept;
23 // Returns: m / day(d).
24 //
25 // constexpr month_day
26 //   operator/(int m, const day& d) noexcept;
27 // Returns: month(m) / d.
28 //
29 // constexpr month_day
30 //   operator/(const day& d, int m) noexcept;
31 // Returns: month(m) / d.
32 
33 
34 #include <chrono>
35 #include <type_traits>
36 #include <cassert>
37 
38 #include "test_macros.h"
39 #include "test_comparisons.h"
40 
41 int main(int, char**)
42 {
43     using month_day = std::chrono::month_day;
44     using month     = std::chrono::month;
45     using day       = std::chrono::day;
46 
47     constexpr month February = std::chrono::February;
48 
49     { // operator/(const month& m, const day& d) (and switched)
50         ASSERT_NOEXCEPT (                    February/day{1});
51         ASSERT_SAME_TYPE(month_day, decltype(February/day{1}));
52         ASSERT_NOEXCEPT (                    day{1}/February);
53         ASSERT_SAME_TYPE(month_day, decltype(day{1}/February));
54 
55         for (int i = 1; i <= 12; ++i)
56             for (unsigned j = 0; j <= 30; ++j)
57             {
58                 month m(i);
59                 day   d{j};
60                 month_day md1 = m/d;
61                 month_day md2 = d/m;
62                 assert(md1.month() == m);
63                 assert(md1.day()   == d);
64                 assert(md2.month() == m);
65                 assert(md2.day()   == d);
66                 assert(md1 == md2);
67             }
68     }
69 
70 
71     { // operator/(const month& m, int d) (NOT switched)
72         ASSERT_NOEXCEPT (                    February/2);
73         ASSERT_SAME_TYPE(month_day, decltype(February/2));
74 
75         for (int i = 1; i <= 12; ++i)
76             for (unsigned j = 0; j <= 30; ++j)
77             {
78                 month m(i);
79                 day   d(j);
80                 month_day md1 = m/j;
81                 assert(md1.month() == m);
82                 assert(md1.day()   == d);
83             }
84     }
85 
86 
87     { // operator/(const day& d, int m) (and switched)
88         ASSERT_NOEXCEPT (                    day{2}/2);
89         ASSERT_SAME_TYPE(month_day, decltype(day{2}/2));
90         ASSERT_NOEXCEPT (                    2/day{2});
91         ASSERT_SAME_TYPE(month_day, decltype(2/day{2}));
92 
93         for (int i = 1; i <= 12; ++i)
94             for (unsigned j = 0; j <= 30; ++j)
95             {
96                 month m(i);
97                 day   d(j);
98                 month_day md1 = d/i;
99                 month_day md2 = i/d;
100                 assert(md1.month() == m);
101                 assert(md1.day()   == d);
102                 assert(md2.month() == m);
103                 assert(md2.day()   == d);
104                 assert(md1 == md2);
105             }
106     }
107 
108   return 0;
109 }
110