| 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_WEEKDAY_H |
| 11 | #define _LIBCPP___CHRONO_MONTH_WEEKDAY_H |
| 12 | |
| 13 | #include <__chrono/month.h> |
| 14 | #include <__chrono/weekday.h> |
| 15 | #include <__config> |
| 16 | #include <__cstddef/size_t.h> |
| 17 | #include <__functional/hash.h> |
| 18 | |
| 19 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 20 | # pragma GCC system_header |
| 21 | #endif |
| 22 | |
| 23 | #if _LIBCPP_STD_VER >= 20 |
| 24 | |
| 25 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 26 | |
| 27 | namespace chrono { |
| 28 | |
| 29 | class month_weekday { |
| 30 | private: |
| 31 | chrono::month __m_; |
| 32 | chrono::weekday_indexed __wdi_; |
| 33 | |
| 34 | public: |
| 35 | _LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval, |
| 36 | const chrono::weekday_indexed& __wdival) noexcept |
| 37 | : __m_{__mval}, __wdi_{__wdival} {} |
| 38 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } |
| 39 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { |
| 40 | return __wdi_; |
| 41 | } |
| 42 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); } |
| 43 | }; |
| 44 | |
| 45 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool |
| 46 | operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept { |
| 47 | return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); |
| 48 | } |
| 49 | |
| 50 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday |
| 51 | operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept { |
| 52 | return month_weekday{__lhs, __rhs}; |
| 53 | } |
| 54 | |
| 55 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday |
| 56 | operator/(int __lhs, const weekday_indexed& __rhs) noexcept { |
| 57 | return month_weekday{month(__lhs), __rhs}; |
| 58 | } |
| 59 | |
| 60 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday |
| 61 | operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept { |
| 62 | return month_weekday{__rhs, __lhs}; |
| 63 | } |
| 64 | |
| 65 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday |
| 66 | operator/(const weekday_indexed& __lhs, int __rhs) noexcept { |
| 67 | return month_weekday{month(__rhs), __lhs}; |
| 68 | } |
| 69 | |
| 70 | class month_weekday_last { |
| 71 | chrono::month __m_; |
| 72 | chrono::weekday_last __wdl_; |
| 73 | |
| 74 | public: |
| 75 | _LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval, |
| 76 | const chrono::weekday_last& __wdlval) noexcept |
| 77 | : __m_{__mval}, __wdl_{__wdlval} {} |
| 78 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; } |
| 79 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { |
| 80 | return __wdl_; |
| 81 | } |
| 82 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); } |
| 83 | }; |
| 84 | |
| 85 | _LIBCPP_HIDE_FROM_ABI inline constexpr bool |
| 86 | operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept { |
| 87 | return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); |
| 88 | } |
| 89 | |
| 90 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last |
| 91 | operator/(const month& __lhs, const weekday_last& __rhs) noexcept { |
| 92 | return month_weekday_last{__lhs, __rhs}; |
| 93 | } |
| 94 | |
| 95 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last |
| 96 | operator/(int __lhs, const weekday_last& __rhs) noexcept { |
| 97 | return month_weekday_last{month(__lhs), __rhs}; |
| 98 | } |
| 99 | |
| 100 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last |
| 101 | operator/(const weekday_last& __lhs, const month& __rhs) noexcept { |
| 102 | return month_weekday_last{__rhs, __lhs}; |
| 103 | } |
| 104 | |
| 105 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last |
| 106 | operator/(const weekday_last& __lhs, int __rhs) noexcept { |
| 107 | return month_weekday_last{month(__rhs), __lhs}; |
| 108 | } |
| 109 | } // namespace chrono |
| 110 | |
| 111 | # if _LIBCPP_STD_VER >= 26 |
| 112 | |
| 113 | template <> |
| 114 | struct hash<chrono::month_weekday> { |
| 115 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday& __mw) noexcept { |
| 116 | return std::__hash_combine( |
| 117 | hash<chrono::month>{}(__mw.month()), hash<chrono::weekday_indexed>{}(__mw.weekday_indexed())); |
| 118 | } |
| 119 | }; |
| 120 | |
| 121 | template <> |
| 122 | struct hash<chrono::month_weekday_last> { |
| 123 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static size_t operator()(const chrono::month_weekday_last& __mwl) noexcept { |
| 124 | return std::__hash_combine( |
| 125 | hash<chrono::month>{}(__mwl.month()), hash<chrono::weekday_last>{}(__mwl.weekday_last())); |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | # endif // _LIBCPP_STD_VER >= 26 |
| 130 | |
| 131 | _LIBCPP_END_NAMESPACE_STD |
| 132 | |
| 133 | #endif // _LIBCPP_STD_VER >= 20 |
| 134 | |
| 135 | #endif // _LIBCPP___CHRONO_MONTH_WEEKDAY_H |
| 136 | |