Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:24

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___CHRONO_MONTHDAY_H
0011 #define _LIBCPP___CXX03___CHRONO_MONTHDAY_H
0012 
0013 #include <__cxx03/__chrono/calendar.h>
0014 #include <__cxx03/__chrono/day.h>
0015 #include <__cxx03/__chrono/month.h>
0016 #include <__cxx03/__config>
0017 #include <__cxx03/compare>
0018 
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 #  pragma GCC system_header
0021 #endif
0022 
0023 #if _LIBCPP_STD_VER >= 20
0024 
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026 
0027 namespace chrono {
0028 
0029 class month_day {
0030 private:
0031   chrono::month __m_;
0032   chrono::day __d_;
0033 
0034 public:
0035   month_day() = default;
0036   _LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
0037       : __m_{__mval}, __d_{__dval} {}
0038   _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
0039   _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; }
0040   _LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
0041 };
0042 
0043 _LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept {
0044   if (!__m_.ok())
0045     return false;
0046   const unsigned __dval = static_cast<unsigned>(__d_);
0047   if (__dval < 1 || __dval > 31)
0048     return false;
0049   if (__dval <= 29)
0050     return true;
0051   //  Now we've got either 30 or 31
0052   const unsigned __mval = static_cast<unsigned>(__m_);
0053   if (__mval == 2)
0054     return false;
0055   if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
0056     return __dval == 30;
0057   return true;
0058 }
0059 
0060 _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept {
0061   return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day();
0062 }
0063 
0064 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
0065 operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
0066   if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
0067     return __c;
0068   return __lhs.day() <=> __rhs.day();
0069 }
0070 
0071 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept {
0072   return month_day{__lhs, __rhs};
0073 }
0074 
0075 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept {
0076   return __rhs / __lhs;
0077 }
0078 
0079 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept {
0080   return __lhs / day(__rhs);
0081 }
0082 
0083 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept {
0084   return month(__lhs) / __rhs;
0085 }
0086 
0087 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept {
0088   return month(__rhs) / __lhs;
0089 }
0090 
0091 class month_day_last {
0092 private:
0093   chrono::month __m_;
0094 
0095 public:
0096   _LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept : __m_{__val} {}
0097   _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
0098   _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); }
0099 };
0100 
0101 _LIBCPP_HIDE_FROM_ABI inline constexpr bool
0102 operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
0103   return __lhs.month() == __rhs.month();
0104 }
0105 
0106 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
0107 operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
0108   return __lhs.month() <=> __rhs.month();
0109 }
0110 
0111 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept {
0112   return month_day_last{__lhs};
0113 }
0114 
0115 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept {
0116   return month_day_last{__rhs};
0117 }
0118 
0119 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept {
0120   return month_day_last{month(__lhs)};
0121 }
0122 
0123 _LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept {
0124   return month_day_last{month(__rhs)};
0125 }
0126 
0127 } // namespace chrono
0128 
0129 _LIBCPP_END_NAMESPACE_STD
0130 
0131 #endif // _LIBCPP_STD_VER >= 20
0132 
0133 #endif // _LIBCPP___CXX03___CHRONO_MONTHDAY_H