month_weekday.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifndef _LIBCPP___CHRONO_MONTH_WEEKDAY_H
  10. #define _LIBCPP___CHRONO_MONTH_WEEKDAY_H
  11. #include <__chrono/month.h>
  12. #include <__chrono/weekday.h>
  13. #include <__config>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. #if _LIBCPP_STD_VER > 17
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. namespace chrono
  20. {
  21. class month_weekday {
  22. private:
  23. chrono::month __m_;
  24. chrono::weekday_indexed __wdi_;
  25. public:
  26. _LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
  27. : __m_{__mval}, __wdi_{__wdival} {}
  28. _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
  29. _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
  30. _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); }
  31. };
  32. _LIBCPP_HIDE_FROM_ABI inline constexpr
  33. bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
  34. { return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
  35. _LIBCPP_HIDE_FROM_ABI inline constexpr
  36. bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
  37. { return !(__lhs == __rhs); }
  38. _LIBCPP_HIDE_FROM_ABI inline constexpr
  39. month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
  40. { return month_weekday{__lhs, __rhs}; }
  41. _LIBCPP_HIDE_FROM_ABI inline constexpr
  42. month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
  43. { return month_weekday{month(__lhs), __rhs}; }
  44. _LIBCPP_HIDE_FROM_ABI inline constexpr
  45. month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
  46. { return month_weekday{__rhs, __lhs}; }
  47. _LIBCPP_HIDE_FROM_ABI inline constexpr
  48. month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
  49. { return month_weekday{month(__rhs), __lhs}; }
  50. class month_weekday_last {
  51. chrono::month __m_;
  52. chrono::weekday_last __wdl_;
  53. public:
  54. _LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
  55. : __m_{__mval}, __wdl_{__wdlval} {}
  56. _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
  57. _LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
  58. _LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); }
  59. };
  60. _LIBCPP_HIDE_FROM_ABI inline constexpr
  61. bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
  62. { return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
  63. _LIBCPP_HIDE_FROM_ABI inline constexpr
  64. bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
  65. { return !(__lhs == __rhs); }
  66. _LIBCPP_HIDE_FROM_ABI inline constexpr
  67. month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
  68. { return month_weekday_last{__lhs, __rhs}; }
  69. _LIBCPP_HIDE_FROM_ABI inline constexpr
  70. month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
  71. { return month_weekday_last{month(__lhs), __rhs}; }
  72. _LIBCPP_HIDE_FROM_ABI inline constexpr
  73. month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
  74. { return month_weekday_last{__rhs, __lhs}; }
  75. _LIBCPP_HIDE_FROM_ABI inline constexpr
  76. month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
  77. { return month_weekday_last{month(__rhs), __lhs}; }
  78. } // namespace chrono
  79. _LIBCPP_END_NAMESPACE_STD
  80. #endif // _LIBCPP_STD_VER > 17
  81. #endif // _LIBCPP___CHRONO_MONTH_WEEKDAY_H