File indexing completed on 2026-05-03 08:13:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___CHRONO_YEAR_H
0011 #define _LIBCPP___CXX03___CHRONO_YEAR_H
0012
0013 #include <__cxx03/__chrono/duration.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/compare>
0016 #include <__cxx03/limits>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_PUSH_MACROS
0023 #include <__cxx03/__undef_macros>
0024
0025 #if _LIBCPP_STD_VER >= 20
0026
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028
0029 namespace chrono {
0030
0031 class year {
0032 private:
0033 short __y_;
0034
0035 public:
0036 year() = default;
0037 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y_(static_cast<short>(__val)) {}
0038
0039 _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept {
0040 ++__y_;
0041 return *this;
0042 }
0043 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept {
0044 year __tmp = *this;
0045 ++(*this);
0046 return __tmp;
0047 }
0048 _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept {
0049 --__y_;
0050 return *this;
0051 }
0052 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept {
0053 year __tmp = *this;
0054 --(*this);
0055 return __tmp;
0056 }
0057 _LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept;
0058 _LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept;
0059 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; }
0060 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; }
0061
0062 _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept {
0063 return __y_ % 4 == 0 && (__y_ % 100 != 0 || __y_ % 400 == 0);
0064 }
0065 _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y_; }
0066 _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
0067 _LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; }
0068 _LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{32767}; }
0069 };
0070
0071 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept {
0072 return static_cast<int>(__lhs) == static_cast<int>(__rhs);
0073 }
0074
0075 _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept {
0076 return static_cast<int>(__lhs) <=> static_cast<int>(__rhs);
0077 }
0078
0079 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept {
0080 return year(static_cast<int>(__lhs) + __rhs.count());
0081 }
0082
0083 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept {
0084 return __rhs + __lhs;
0085 }
0086
0087 _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept {
0088 return __lhs + -__rhs;
0089 }
0090
0091 _LIBCPP_HIDE_FROM_ABI inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept {
0092 return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)};
0093 }
0094
0095 _LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator+=(const years& __dy) noexcept {
0096 *this = *this + __dy;
0097 return *this;
0098 }
0099
0100 _LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator-=(const years& __dy) noexcept {
0101 *this = *this - __dy;
0102 return *this;
0103 }
0104
0105 _LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept {
0106 static_assert(static_cast<int>(std::numeric_limits<decltype(__y_)>::max()) == static_cast<int>(max()));
0107 return static_cast<int>(min()) <= __y_;
0108 }
0109
0110 }
0111
0112 _LIBCPP_END_NAMESPACE_STD
0113
0114 #endif
0115
0116 _LIBCPP_POP_MACROS
0117
0118 #endif