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