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