• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 
10 // <chrono>
11 // class day;
12 
13 // constexpr day operator+(const day& x, const days& y) noexcept;
14 //   Returns: day(unsigned{x} + y.count()).
15 //
16 // constexpr day operator+(const days& x, const day& y) noexcept;
17 //   Returns: y + x.
18 
19 
20 #include <chrono>
21 #include <type_traits>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 template <typename D, typename Ds>
testConstexpr()27 constexpr bool testConstexpr()
28 {
29     D d{1};
30     Ds offset{23};
31     if (d + offset != D{24}) return false;
32     if (offset + d != D{24}) return false;
33     return true;
34 }
35 
main(int,char **)36 int main(int, char**)
37 {
38     using day  = std::chrono::day;
39     using days = std::chrono::days;
40 
41     ASSERT_NOEXCEPT(std::declval<day>() + std::declval<days>());
42     ASSERT_NOEXCEPT(std::declval<days>() + std::declval<day>());
43 
44     ASSERT_SAME_TYPE(day, decltype(std::declval<day>() + std::declval<days>()));
45     ASSERT_SAME_TYPE(day, decltype(std::declval<days>() + std::declval<day>()));
46 
47     static_assert(testConstexpr<day, days>(), "");
48 
49     day dy{12};
50     for (unsigned i = 0; i <= 10; ++i)
51     {
52         day d1 = dy + days{i};
53         day d2 = days{i} + dy;
54         assert(d1 == d2);
55         assert(static_cast<unsigned>(d1) == i + 12);
56         assert(static_cast<unsigned>(d2) == i + 12);
57     }
58 
59   return 0;
60 }
61