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