Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.year/time.cal.year.members/plus_minus_equal.pass.cpp

raw
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 year;
12
13 // constexpr year& operator+=(const years& d) noexcept;
14 // constexpr year& operator-=(const years& d) noexcept;
15
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 using year = std::chrono::year;
23 using years = std::chrono::years;
24
25 constexpr bool test() {
26 for (int i = 10000; i <= 10020; ++i) {
27 year yr(i);
28 assert(static_cast<int>(yr += years{10}) == i + 10);
29 assert(static_cast<int>(yr) == i + 10);
30 assert(static_cast<int>(yr -= years{9}) == i + 1);
31 assert(static_cast<int>(yr) == i + 1);
32 }
33
34 return true;
35 }
36
37 int main(int, char**) {
38 ASSERT_NOEXCEPT(std::declval<year&>() += std::declval<years>());
39 ASSERT_NOEXCEPT(std::declval<year&>() -= std::declval<years>());
40
41 ASSERT_SAME_TYPE(year&, decltype(std::declval<year&>() += std::declval<years>()));
42 ASSERT_SAME_TYPE(year&, decltype(std::declval<year&>() -= std::declval<years>()));
43
44 test();
45 static_assert(test());
46
47 return 0;
48 }