• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10 
11 // <chrono>
12 // class weekday;
13 
14 //  constexpr weekday& operator++() noexcept;
15 //  constexpr weekday operator++(int) noexcept;
16 
17 
18 #include <chrono>
19 #include <type_traits>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "../../euclidian.h"
24 
25 template <typename WD>
testConstexpr()26 constexpr bool testConstexpr()
27 {
28     WD wd{5};
29     if (static_cast<unsigned>(++wd) != 6) return false;
30     if (static_cast<unsigned>(wd++) != 6) return false;
31     if (static_cast<unsigned>(wd)   != 0) return false;
32     return true;
33 }
34 
main()35 int main()
36 {
37     using weekday = std::chrono::weekday;
38     ASSERT_NOEXCEPT(++(std::declval<weekday&>())  );
39     ASSERT_NOEXCEPT(  (std::declval<weekday&>())++);
40 
41     ASSERT_SAME_TYPE(weekday , decltype(  std::declval<weekday&>()++));
42     ASSERT_SAME_TYPE(weekday&, decltype(++std::declval<weekday&>()  ));
43 
44     static_assert(testConstexpr<weekday>(), "");
45 
46     for (unsigned i = 0; i <= 6; ++i)
47     {
48         weekday wd(i);
49         assert((static_cast<unsigned>(++wd) == euclidian_addition<unsigned, 0, 6>(i, 1)));
50         assert((static_cast<unsigned>(wd++) == euclidian_addition<unsigned, 0, 6>(i, 1)));
51         assert((static_cast<unsigned>(wd)   == euclidian_addition<unsigned, 0, 6>(i, 2)));
52     }
53 }
54