Home | History | Annotate | Download | only in time.cal.day.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 day;
     13 
     14 // constexpr day operator+(const day& x, const days& y) noexcept;
     15 //   Returns: day(unsigned{x} + y.count()).
     16 //
     17 // constexpr day operator+(const days& x, const day& y) noexcept;
     18 //   Returns: y + x.
     19 
     20 
     21 #include <chrono>
     22 #include <type_traits>
     23 #include <cassert>
     24 
     25 #include "test_macros.h"
     26 
     27 template <typename D, typename Ds>
     28 constexpr bool testConstexpr()
     29 {
     30     D d{1};
     31     Ds offset{23};
     32     if (d + offset != D{24}) return false;
     33     if (offset + d != D{24}) return false;
     34     return true;
     35 }
     36 
     37 int main()
     38 {
     39     using day  = std::chrono::day;
     40     using days = std::chrono::days;
     41 
     42     ASSERT_NOEXCEPT(std::declval<day>() + std::declval<days>());
     43     ASSERT_NOEXCEPT(std::declval<days>() + std::declval<day>());
     44 
     45     ASSERT_SAME_TYPE(day, decltype(std::declval<day>() + std::declval<days>()));
     46     ASSERT_SAME_TYPE(day, decltype(std::declval<days>() + std::declval<day>()));
     47 
     48     static_assert(testConstexpr<day, days>(), "");
     49 
     50     day dy{12};
     51     for (unsigned i = 0; i <= 10; ++i)
     52     {
     53         day d1 = dy + days{i};
     54         day d2 = days{i} + dy;
     55         assert(d1 == d2);
     56         assert(static_cast<unsigned>(d1) == i + 12);
     57         assert(static_cast<unsigned>(d2) == i + 12);
     58     }
     59 }
     60