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#include <chrono>
20#include <cassert>
21#include <type_traits>
22#include <utility>
23
24#include "test_macros.h"
25
26using day = std::chrono::day;
27using days = std::chrono::days;
28
29constexpr bool test() {
30 day dy{12};
31 for (unsigned i = 0; i <= 10; ++i) {
32 day d1 = dy + days{i};
33 day d2 = days{i} + dy;
34 assert(d1 == d2);
35 assert(static_cast<unsigned>(d1) == i + 12);
36 assert(static_cast<unsigned>(d2) == i + 12);
37 }
38
39 return true;
40}
41
42int main(int, char**) {
43 ASSERT_NOEXCEPT(std::declval<day>() + std::declval<days>());
44 ASSERT_NOEXCEPT(std::declval<days>() + std::declval<day>());
45
46 ASSERT_SAME_TYPE(day, decltype(std::declval<day>() + std::declval<days>()));
47 ASSERT_SAME_TYPE(day, decltype(std::declval<days>() + std::declval<day>()));
48
49 test();
50 static_assert(test());
51
52 return 0;
53}
54

source code of libcxx/test/std/time/time.cal/time.cal.day/time.cal.day.nonmembers/plus.pass.cpp