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_weekday;
12 
13 // constexpr month_weekday
14 //   operator/(const month& m, const weekday_indexed& wdi) noexcept;
15 // Returns: {m, wdi}.
16 //
17 // constexpr month_weekday
18 //   operator/(int m, const weekday_indexed& wdi) noexcept;
19 // Returns: month(m) / wdi.
20 //
21 // constexpr month_weekday
22 //   operator/(const weekday_indexed& wdi, const month& m) noexcept;
23 // Returns: m / wdi. constexpr month_weekday
24 //
25 // constexpr month_weekday
26 //   operator/(const weekday_indexed& wdi, int m) noexcept;
27 // Returns: month(m) / wdi.
28 
29 
30 //
31 // [Example:
32 // constexpr auto mwd = February/Tuesday[3]; // mwd is the third Tuesday of February of an as yet unspecified year
33 //      static_assert(mwd.month() == February);
34 //      static_assert(mwd.weekday_indexed() == Tuesday[3]);
35 // —end example]
36 
37 
38 
39 
40 #include <chrono>
41 #include <type_traits>
42 #include <cassert>
43 
44 #include "test_macros.h"
45 #include "test_comparisons.h"
46 
47 int main(int, char**)
48 {
49     using month_weekday   = std::chrono::month_weekday;
50     using month           = std::chrono::month;
51     using weekday         = std::chrono::weekday;
52     using weekday_indexed = std::chrono::weekday_indexed;
53 
54     constexpr weekday Tuesday = std::chrono::Tuesday;
55     constexpr month February = std::chrono::February;
56 
57     { // operator/(const month& m, const weekday_indexed& wdi) (and switched)
58         ASSERT_NOEXCEPT (February/Tuesday[2]);
59         ASSERT_SAME_TYPE(month_weekday, decltype(February/Tuesday[2]));
60         ASSERT_NOEXCEPT (Tuesday[2]/February);
61         ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/February));
62 
63     //  Run the example
64         {
65         constexpr month_weekday wdi = February/Tuesday[3];
66         static_assert(wdi.month()           == February,   "");
67         static_assert(wdi.weekday_indexed() == Tuesday[3], "");
68         }
69 
70         for (int i = 1; i <= 12; ++i)
71             for (unsigned j = 0; j <= 6; ++j)
72                 for (unsigned k = 1; k <= 5; ++k)
73                 {
74                     month m(i);
75                     weekday_indexed wdi = weekday{j}[k];
76                     month_weekday mwd1 = m/wdi;
77                     month_weekday mwd2 = wdi/m;
78                     assert(mwd1.month() == m);
79                     assert(mwd1.weekday_indexed() == wdi);
80                     assert(mwd2.month() == m);
81                     assert(mwd2.weekday_indexed() == wdi);
82                     assert(mwd1 == mwd2);
83                 }
84     }
85 
86 
87     { // operator/(int m, const weekday_indexed& wdi) (and switched)
88         ASSERT_NOEXCEPT (2/Tuesday[2]);
89         ASSERT_SAME_TYPE(month_weekday, decltype(2/Tuesday[2]));
90         ASSERT_NOEXCEPT (Tuesday[2]/2);
91         ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/2));
92 
93     //  Run the example
94         {
95         constexpr month_weekday wdi = 2/Tuesday[3];
96         static_assert(wdi.month()           == February,   "");
97         static_assert(wdi.weekday_indexed() == Tuesday[3], "");
98         }
99 
100         for (int i = 1; i <= 12; ++i)
101             for (unsigned j = 0; j <= 6; ++j)
102                 for (unsigned k = 1; k <= 5; ++k)
103                 {
104                     weekday_indexed wdi = weekday{j}[k];
105                     month_weekday mwd1 = i/wdi;
106                     month_weekday mwd2 = wdi/i;
107                     assert(mwd1.month() == month(i));
108                     assert(mwd1.weekday_indexed() == wdi);
109                     assert(mwd2.month() == month(i));
110                     assert(mwd2.weekday_indexed() == wdi);
111                     assert(mwd1 == mwd2);
112                 }
113     }
114 
115   return 0;
116 }
117