minus.pass.cpp (1908B)
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; 13 14 // constexpr year operator-(const year& x, const years& y) noexcept; 15 // Returns: x + -y. 16 // 17 // constexpr years operator-(const year& x, const year& y) noexcept; 18 // Returns: If x.ok() == true and y.ok() == true, returns a value m in the range 19 // [years{0}, years{11}] satisfying y + m == x. 20 // Otherwise the value returned is unspecified. 21 // [Example: January - February == years{11}. —end example] 22 23 extern "C" int printf(const char *, ...); 24 25 #include <chrono> 26 #include <type_traits> 27 #include <cassert> 28 29 #include "test_macros.h" 30 31 template <typename Y, typename Ys> 32 constexpr bool testConstexpr() 33 { 34 Y y{2313}; 35 Ys offset{1006}; 36 if (y - offset != Y{1307}) return false; 37 if (y - Y{1307} != offset) return false; 38 return true; 39 } 40 41 int main() 42 { 43 using year = std::chrono::year; 44 using years = std::chrono::years; 45 46 ASSERT_NOEXCEPT( std::declval<year>() - std::declval<years>()); 47 ASSERT_SAME_TYPE(year , decltype(std::declval<year>() - std::declval<years>())); 48 49 ASSERT_NOEXCEPT( std::declval<year>() - std::declval<year>()); 50 ASSERT_SAME_TYPE(years, decltype(std::declval<year>() - std::declval<year>())); 51 52 static_assert(testConstexpr<year, years>(), ""); 53 54 year y{1223}; 55 for (int i = 1100; i <= 1110; ++i) 56 { 57 year y1 = y - years{i}; 58 years ys1 = y - year{i}; 59 assert(static_cast<int>(y1) == 1223 - i); 60 assert(ys1.count() == 1223 - i); 61 } 62 }