Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.members/decrement.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 month;
12
13 // constexpr month& operator--() noexcept;
14 // constexpr month operator--(int) noexcept;
15
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 constexpr bool test() {
23 using month = std::chrono::month;
24 for (unsigned i = 0; i <= 15; ++i) {
25 month m1(i);
26 month m2 = m1--;
27 assert(m1.ok());
28 assert(m1 != m2);
29
30 unsigned exp = i == 0 ? 11 : i == 1 ? 12 : i - 1;
31 while (exp > 12)
32 exp -= 12;
33 assert(static_cast<unsigned>(m1) == exp);
34 }
35 for (unsigned i = 0; i <= 15; ++i) {
36 month m1(i);
37 month m2 = --m1;
38 assert(m1.ok());
39 assert(m2.ok());
40 assert(m1 == m2);
41
42 unsigned exp = i == 0 ? 11 : i == 1 ? 12 : i - 1;
43 while (exp > 12)
44 exp -= 12;
45 assert(static_cast<unsigned>(m1) == exp);
46 }
47
48 return true;
49 }
50
51 int main(int, char**) {
52 using month = std::chrono::month;
53
54 ASSERT_NOEXCEPT(--(std::declval<month&>()));
55 ASSERT_NOEXCEPT((std::declval<month&>())--);
56
57 ASSERT_SAME_TYPE(month, decltype(std::declval<month&>()--));
58 ASSERT_SAME_TYPE(month&, decltype(--std::declval<month&>()));
59
60 test();
61 static_assert(test());
62
63 return 0;
64 }