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 46 int main(int, char**) 47 { 48 using month_weekday = std::chrono::month_weekday; 49 using month = std::chrono::month; 50 using weekday = std::chrono::weekday; 51 using weekday_indexed = std::chrono::weekday_indexed; 52 53 constexpr weekday Tuesday = std::chrono::Tuesday; 54 constexpr month February = std::chrono::February; 55 56 { // operator/(const month& m, const weekday_indexed& wdi) (and switched) 57 ASSERT_NOEXCEPT (February/Tuesday[2]); 58 ASSERT_SAME_TYPE(month_weekday, decltype(February/Tuesday[2])); 59 ASSERT_NOEXCEPT (Tuesday[2]/February); 60 ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/February)); 61 62 // Run the example 63 { 64 constexpr month_weekday wdi = February/Tuesday[3]; 65 static_assert(wdi.month() == February, ""); 66 static_assert(wdi.weekday_indexed() == Tuesday[3], ""); 67 } 68 69 for (int i = 1; i <= 12; ++i) 70 for (unsigned j = 0; j <= 6; ++j) 71 for (unsigned k = 1; k <= 5; ++k) 72 { 73 month m(i); 74 weekday_indexed wdi = weekday{j}[k]; 75 month_weekday mwd1 = m/wdi; 76 month_weekday mwd2 = wdi/m; 77 assert(mwd1.month() == m); 78 assert(mwd1.weekday_indexed() == wdi); 79 assert(mwd2.month() == m); 80 assert(mwd2.weekday_indexed() == wdi); 81 assert(mwd1 == mwd2); 82 } 83 } 84 85 86 { // operator/(int m, const weekday_indexed& wdi) (and switched) 87 ASSERT_NOEXCEPT (2/Tuesday[2]); 88 ASSERT_SAME_TYPE(month_weekday, decltype(2/Tuesday[2])); 89 ASSERT_NOEXCEPT (Tuesday[2]/2); 90 ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/2)); 91 92 // Run the example 93 { 94 constexpr month_weekday wdi = 2/Tuesday[3]; 95 static_assert(wdi.month() == February, ""); 96 static_assert(wdi.weekday_indexed() == Tuesday[3], ""); 97 } 98 99 for (int i = 1; i <= 12; ++i) 100 for (unsigned j = 0; j <= 6; ++j) 101 for (unsigned k = 1; k <= 5; ++k) 102 { 103 weekday_indexed wdi = weekday{j}[k]; 104 month_weekday mwd1 = i/wdi; 105 month_weekday mwd2 = wdi/i; 106 assert(mwd1.month() == month(i)); 107 assert(mwd1.weekday_indexed() == wdi); 108 assert(mwd2.month() == month(i)); 109 assert(mwd2.weekday_indexed() == wdi); 110 assert(mwd1 == mwd2); 111 } 112 } 113 114 return 0; 115 } 116