plus_minus_equal_month.pass.cpp (2714B)
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 year_month_day_last; 13 14 // constexpr year_month_day_last& operator+=(const months& m) noexcept; 15 // constexpr year_month_day_last& operator-=(const months& m) noexcept; 16 17 #include <chrono> 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 23 template <typename D, typename Ds> 24 constexpr bool testConstexpr(D d1) 25 { 26 if (static_cast<unsigned>((d1 ).month()) != 1) return false; 27 if (static_cast<unsigned>((d1 += Ds{ 1}).month()) != 2) return false; 28 if (static_cast<unsigned>((d1 += Ds{ 2}).month()) != 4) return false; 29 if (static_cast<unsigned>((d1 += Ds{12}).month()) != 4) return false; 30 if (static_cast<unsigned>((d1 -= Ds{ 1}).month()) != 3) return false; 31 if (static_cast<unsigned>((d1 -= Ds{ 2}).month()) != 1) return false; 32 if (static_cast<unsigned>((d1 -= Ds{12}).month()) != 1) return false; 33 return true; 34 } 35 36 int main() 37 { 38 using year = std::chrono::year; 39 using month = std::chrono::month; 40 using month_day_last = std::chrono::month_day_last; 41 using year_month_day_last = std::chrono::year_month_day_last; 42 using months = std::chrono::months; 43 44 ASSERT_NOEXCEPT(std::declval<year_month_day_last&>() += std::declval<months>()); 45 ASSERT_NOEXCEPT(std::declval<year_month_day_last&>() -= std::declval<months>()); 46 47 ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval<year_month_day_last&>() += std::declval<months>())); 48 ASSERT_SAME_TYPE(year_month_day_last&, decltype(std::declval<year_month_day_last&>() -= std::declval<months>())); 49 50 static_assert(testConstexpr<year_month_day_last, months>(year_month_day_last{year{1234}, month_day_last{month{1}}}), ""); 51 52 for (unsigned i = 0; i <= 10; ++i) 53 { 54 year y{1234}; 55 month_day_last mdl{month{i}}; 56 year_month_day_last ym(y, mdl); 57 assert(static_cast<unsigned>((ym += months{2}).month()) == i + 2); 58 assert(ym.year() == y); 59 assert(static_cast<unsigned>((ym ).month()) == i + 2); 60 assert(ym.year() == y); 61 assert(static_cast<unsigned>((ym -= months{1}).month()) == i + 1); 62 assert(ym.year() == y); 63 assert(static_cast<unsigned>((ym ).month()) == i + 1); 64 assert(ym.year() == y); 65 } 66 }