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 // <chrono> 11 // class year_month_day_last; 12 13 // constexpr year_month_day_last 14 // operator/(const year_month& ym, last_spec) noexcept; 15 // Returns: {ym.year(), month_day_last{ym.month()}}. 16 17 18 // constexpr year_month_day_last 19 // operator/(const year& y, const month_day_last& mdl) noexcept; 20 // Returns: {y, mdl}. 21 // 22 // constexpr year_month_day_last 23 // operator/(int y, const month_day_last& mdl) noexcept; 24 // Returns: year(y) / mdl. 25 // 26 // constexpr year_month_day_last 27 // operator/(const month_day_last& mdl, const year& y) noexcept; 28 // Returns: y / mdl. 29 // 30 // constexpr year_month_day_last 31 // operator/(const month_day_last& mdl, int y) noexcept; 32 // Returns: year(y) / mdl. 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 = std::chrono::month; 45 using year_month = std::chrono::year_month; 46 using year = std::chrono::year; 47 using month_day_last = std::chrono::month_day_last; 48 using year_month_day_last = std::chrono::year_month_day_last; 49 50 constexpr month February = std::chrono::February; 51 constexpr std::chrono::last_spec last = std::chrono::last; 52 53 { // operator/(const year_month& ym, last_spec) 54 constexpr year_month Feb2018{year{2018}, February}; 55 56 ASSERT_NOEXCEPT ( Feb2018/last); 57 ASSERT_SAME_TYPE(year_month_day_last, decltype(Feb2018/last)); 58 59 static_assert((Feb2018/last).year() == year{2018}, ""); 60 static_assert((Feb2018/last).month() == February, ""); 61 62 for (int i = 1000; i < 1010; ++i) 63 for (unsigned j = 1; j <= 12; ++j) 64 { 65 year y{i}; 66 month m{j}; 67 year_month_day_last ymdl = year_month{y,m}/last; 68 assert(ymdl.year() == y); 69 assert(ymdl.month() == m); 70 } 71 } 72 73 74 { // operator/(const year& y, const month_day_last& mdl) (and switched) 75 ASSERT_NOEXCEPT ( year{2018}/month_day_last{February}); 76 ASSERT_SAME_TYPE(year_month_day_last, decltype(year{2018}/month_day_last{February})); 77 ASSERT_NOEXCEPT ( month_day_last{February}/year{2018}); 78 ASSERT_SAME_TYPE(year_month_day_last, decltype(month_day_last{February}/year{2018})); 79 80 static_assert((year{2018}/month_day_last{February}).month() == February, ""); 81 static_assert((year{2018}/month_day_last{February}).year() == year{2018}, ""); 82 static_assert((month_day_last{February}/year{2018}).month() == February, ""); 83 static_assert((month_day_last{February}/year{2018}).year() == year{2018}, ""); 84 85 for (int i = 1000; i < 1010; ++i) 86 for (unsigned j = 1; j <= 12; ++j) 87 { 88 year y{i}; 89 month m{j}; 90 year_month_day_last ymdl1 = y/month_day_last{m}; 91 year_month_day_last ymdl2 = month_day_last{m}/y; 92 assert(ymdl1.month() == m); 93 assert(ymdl2.month() == m); 94 assert(ymdl2.year() == y); 95 assert(ymdl1.year() == y); 96 assert(ymdl1 == ymdl2); 97 } 98 } 99 100 { // operator/(int y, const month_day_last& mdl) (and switched) 101 ASSERT_NOEXCEPT ( 2018/month_day_last{February}); 102 ASSERT_SAME_TYPE(year_month_day_last, decltype(2018/month_day_last{February})); 103 ASSERT_NOEXCEPT ( month_day_last{February}/2018); 104 ASSERT_SAME_TYPE(year_month_day_last, decltype(month_day_last{February}/2018)); 105 106 static_assert((2018/month_day_last{February}).month() == February, ""); 107 static_assert((2018/month_day_last{February}).year() == year{2018}, ""); 108 static_assert((month_day_last{February}/2018).month() == February, ""); 109 static_assert((month_day_last{February}/2018).year() == year{2018}, ""); 110 111 for (int i = 1000; i < 1010; ++i) 112 for (unsigned j = 1; j <= 12; ++j) 113 { 114 year y{i}; 115 month m{j}; 116 year_month_day_last ymdl1 = i/month_day_last{m}; 117 year_month_day_last ymdl2 = month_day_last{m}/i; 118 assert(ymdl1.month() == m); 119 assert(ymdl2.month() == m); 120 assert(ymdl2.year() == y); 121 assert(ymdl1.year() == y); 122 assert(ymdl1 == ymdl2); 123 } 124 } 125 } 126