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