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