Debian Codegraph @

libcxx/include/__chrono/month.h

raw
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef _LIBCPP___CHRONO_MONTH_H
11 #define _LIBCPP___CHRONO_MONTH_H
12
13 #include <__chrono/duration.h>
14 #include <__config>
15 #include <compare>
16
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
19 #endif
20
21 #if _LIBCPP_STD_VER >= 20
22
23 _LIBCPP_BEGIN_NAMESPACE_STD
24
25 namespace chrono {
26
27 class month {
28 private:
29 unsigned char __m_;
30
31 public:
32 month() = default;
33 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept
34 : __m_(static_cast<unsigned char>(__val)) {}
35 _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept {
36 *this += months{1};
37 return *this;
38 }
39 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept {
40 month __tmp = *this;
41 ++(*this);
42 return __tmp;
43 }
44 _LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept {
45 *this -= months{1};
46 return *this;
47 }
48 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept {
49 month __tmp = *this;
50 --(*this);
51 return __tmp;
52 }
53 _LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept;
54 _LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept;
55 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; }
56 _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; }
57 };
58
59 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept {
60 return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs);
61 }
62
63 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
64 return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
65 }
66
67 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept {
68 auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
69 auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
70 return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
71 }
72
73 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept {
74 return __rhs + __lhs;
75 }
76
77 _LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept {
78 return __lhs + -__rhs;
79 }
80
81 _LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept {
82 auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
83 return months(__dm <= 11 ? __dm : __dm + 12);
84 }
85
86 _LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator+=(const months& __dm) noexcept {
87 *this = *this + __dm;
88 return *this;
89 }
90
91 _LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator-=(const months& __dm) noexcept {
92 *this = *this - __dm;
93 return *this;
94 }
95
96 inline constexpr month January{1};
97 inline constexpr month February{2};
98 inline constexpr month March{3};
99 inline constexpr month April{4};
100 inline constexpr month May{5};
101 inline constexpr month June{6};
102 inline constexpr month July{7};
103 inline constexpr month August{8};
104 inline constexpr month September{9};
105 inline constexpr month October{10};
106 inline constexpr month November{11};
107 inline constexpr month December{12};
108
109 } // namespace chrono
110
111 _LIBCPP_END_NAMESPACE_STD
112
113 #endif // _LIBCPP_STD_VER >= 20
114
115 #endif // _LIBCPP___CHRONO_MONTH_H