Home | History | Annotate | Download | only in time.cal.month.nonmembers
      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;
     13 
     14 // constexpr month operator-(const month& x, const months& y) noexcept;
     15 //   Returns: x + -y.
     16 //
     17 // constexpr months operator-(const month& x, const month& y) noexcept;
     18 //   Returns: If x.ok() == true and y.ok() == true, returns a value m in the range
     19 //   [months{0}, months{11}] satisfying y + m == x.
     20 //   Otherwise the value returned is unspecified.
     21 //   [Example: January - February == months{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 M, typename Ms>
     32 constexpr bool testConstexpr()
     33 {
     34     {
     35     M m{5};
     36     Ms offset{3};
     37     if (m - offset != M{2}) return false;
     38     if (m - M{2} != offset) return false;
     39     }
     40 
     41 //  Check the example
     42     if (M{1} - M{2} != Ms{11}) return false;
     43     return true;
     44 }
     45 
     46 #include <iostream>
     47 
     48 int main()
     49 {
     50     using month  = std::chrono::month;
     51     using months = std::chrono::months;
     52 
     53     ASSERT_NOEXCEPT(std::declval<month>() - std::declval<months>());
     54     ASSERT_NOEXCEPT(std::declval<month>() - std::declval<month>());
     55 
     56     ASSERT_SAME_TYPE(month , decltype(std::declval<month>() - std::declval<months>()));
     57     ASSERT_SAME_TYPE(months, decltype(std::declval<month>() - std::declval<month> ()));
     58 
     59 static_assert(testConstexpr<month, months>(), "");
     60 
     61     month m{6};
     62     for (unsigned i = 1; i <= 12; ++i)
     63     {
     64         month m1   = m - months{i};
     65 //      months off = m - month {i};
     66         int exp = 6 - i;
     67         if (exp < 1)
     68             exp += 12;
     69         assert(static_cast<unsigned>(m1) == static_cast<unsigned>(exp));
     70 //          assert(off.count()               == static_cast<unsigned>(exp));
     71     }
     72 }
     73