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 template <typename M, typename Ms>
testConstexpr()24 constexpr bool testConstexpr()
25 {
26     M m1{1};
27     if ((m1 += Ms{ 1}).c_encoding() !=  2) return false;
28     if ((m1 += Ms{ 2}).c_encoding() !=  4) return false;
29     if ((m1 += Ms{ 4}).c_encoding() !=  1) return false;
30     if ((m1 -= Ms{ 1}).c_encoding() !=  0) return false;
31     if ((m1 -= Ms{ 2}).c_encoding() !=  5) return false;
32     if ((m1 -= Ms{ 4}).c_encoding() !=  1) return false;
33     return true;
34 }
35 
main(int,char **)36 int main(int, char**)
37 {
38     using weekday = std::chrono::weekday;
39     using days    = std::chrono::days;
40 
41     ASSERT_NOEXCEPT(                    std::declval<weekday&>() += std::declval<days&>());
42     ASSERT_SAME_TYPE(weekday&, decltype(std::declval<weekday&>() += std::declval<days&>()));
43 
44     ASSERT_NOEXCEPT(                    std::declval<weekday&>() -= std::declval<days&>());
45     ASSERT_SAME_TYPE(weekday&, decltype(std::declval<weekday&>() -= std::declval<days&>()));
46 
47     static_assert(testConstexpr<weekday, days>(), "");
48 
49     for (unsigned i = 0; i <= 6; ++i)
50     {
51         weekday wd(i);
52         assert(((wd += days{3}).c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 3)));
53         assert(((wd)           .c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 3)));
54     }
55 
56     for (unsigned i = 0; i <= 6; ++i)
57     {
58         weekday wd(i);
59         assert(((wd -= days{4}).c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
60         assert(((wd)           .c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
61     }
62 
63   return 0;
64 }
65