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; 13 14 // constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; 15 // Returns: ymd + (-dy) 16 17 18 #include <chrono> 19 #include <type_traits> 20 #include <cassert> 21 22 #include "test_macros.h" 23 24 #include <iostream> 25 26 constexpr bool test_constexpr () 27 { 28 std::chrono::year_month_day ym0{std::chrono::year{1234}, std::chrono::January, std::chrono::day{12}}; 29 std::chrono::year_month_day ym1 = ym0 - std::chrono::years{10}; 30 return 31 ym1.year() == std::chrono::year{1234-10} 32 && ym1.month() == std::chrono::January 33 && ym1.day() == std::chrono::day{12} 34 ; 35 } 36 37 int main() 38 { 39 using year = std::chrono::year; 40 using month = std::chrono::month; 41 using day = std::chrono::day; 42 using year_month_day = std::chrono::year_month_day; 43 using years = std::chrono::years; 44 45 ASSERT_NOEXCEPT( std::declval<year_month_day>() - std::declval<years>()); 46 ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() - std::declval<years>())); 47 48 constexpr month January = std::chrono::January; 49 50 static_assert(test_constexpr(), ""); 51 52 year_month_day ym{year{1234}, January, day{10}}; 53 for (int i = 0; i <= 10; ++i) 54 { 55 year_month_day ym1 = ym - years{i}; 56 assert(static_cast<int>(ym1.year()) == 1234 - i); 57 assert(ym1.month() == January); 58 assert(ym1.day() == day{10}); 59 } 60 } 61