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