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