Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.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 weekday;
12
13 // constexpr weekday& operator+=(const days& d) noexcept;
14 // constexpr weekday& operator-=(const days& d) noexcept;
15
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "../../euclidian.h"
22
23 using weekday = std::chrono::weekday;
24 using days = std::chrono::days;
25
26 constexpr bool test() {
27 for (unsigned i = 0; i <= 6; ++i) {
28 weekday wd(i);
29 assert(((wd += days{3}).c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 3)));
30 assert(((wd).c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 3)));
31 }
32
33 for (unsigned i = 0; i <= 6; ++i) {
34 weekday wd(i);
35 assert(((wd -= days{4}).c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
36 assert(((wd).c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
37 }
38
39 return true;
40 }
41
42 int main(int, char**) {
43 ASSERT_NOEXCEPT(std::declval<weekday&>() += std::declval<days&>());
44 ASSERT_SAME_TYPE(weekday&, decltype(std::declval<weekday&>() += std::declval<days&>()));
45
46 ASSERT_NOEXCEPT(std::declval<weekday&>() -= std::declval<days&>());
47 ASSERT_SAME_TYPE(weekday&, decltype(std::declval<weekday&>() -= std::declval<days&>()));
48
49 test();
50 static_assert(test());
51
52 return 0;
53 }