Skip to content

Commit

Permalink
[libc++][chrono] Uses operator<=> in the calendar.
Browse files Browse the repository at this point in the history
Since the calendar is added in C++20 the existing operators are removed.

Implements part of:
- P1614R2 The Mothership has Landed

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D129887
  • Loading branch information
mordante committed Jul 27, 2022
1 parent f6a7d7e commit 41f7bb9
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 393 deletions.
21 changes: 9 additions & 12 deletions libcxx/docs/Status/SpaceshipProjects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,28 @@ Section,Description,Dependencies,Assignee,Complete
| `[range.iota.iterator] <https://wg21.link/range.iota.iterator>`_,| ranges::iota_view::iterator,[concepts.cmp],Unassigned,|Not Started|
| `[range.transform.iterator] <https://wg21.link/range.transform.iterator>`_,| ranges::transform_view::iterator,[concepts.cmp],Unassigned,|Not Started|
| `[range.elements.iterator] <https://wg21.link/range.elements.iterator>`_,| ranges::elements_view::iterator,[concepts.cmp],Unassigned,|Not Started|
"| `[time.duration.comparisons] <https://wg21.link/time.duration.comparisons>`_
| `[time.point.comparisons] <https://wg21.link/time.point.comparisons>`_
| `[time.cal.day.nonmembers] <https://wg21.link/time.cal.day.nonmembers>`_
| `[time.duration.comparisons] <https://wg21.link/time.duration.comparisons>`_, "chrono::duration", None, Mark de Wever, |Not Started|
| `[time.point.comparisons] <https://wg21.link/time.point.comparisons>`_, "chrono::point", None, Mark de Wever, |Not Started|
"| `[time.cal.day.nonmembers] <https://wg21.link/time.cal.day.nonmembers>`_
| `[time.cal.month.nonmembers] <https://wg21.link/time.cal.month.nonmembers>`_
| `[time.cal.year.nonmembers] <https://wg21.link/time.cal.year.nonmembers>`_
| `[time.cal.md.nonmembers] <https://wg21.link/time.cal.md.nonmembers>`_
| `[time.cal.mdlast] <https://wg21.link/time.cal.mdlast>`_
| `[time.cal.ym.nonmembers] <https://wg21.link/time.cal.ym.nonmembers>`_
| `[time.cal.ymd.nonmembers] <https://wg21.link/time.cal.ymd.nonmembers>`_
| `[time.cal.ymdlast.nonmembers] <https://wg21.link/time.cal.ymdlast.nonmembers>`_
| `[time.zone.nonmembers] <https://wg21.link/time.zone.nonmembers>`_
| `[time.zone.leap.nonmembers] <https://wg21.link/time.zone.leap.nonmembers>`_
| `[time.zone.link.nonmembers] <https://wg21.link/time.zone.link.nonmembers>`_","| chrono::duration
| chrono::time_point
| chrono::day
| `[time.cal.ymdlast.nonmembers] <https://wg21.link/time.cal.ymdlast.nonmembers>`_","| chrono::day
| chrono::month
| chrono::year
| chrono::month_day
| chrono::month_day_last
| chrono::year_month
| chrono::year_month_day
| chrono::year_month_day_last
| chrono::time_zone
| chrono::year_month_day_last",None,Mark de Wever,|Complete|
"| `[time.zone.nonmembers] <https://wg21.link/time.zone.nonmembers>`_
| `[time.zone.leap.nonmembers] <https://wg21.link/time.zone.leap.nonmembers>`_
| `[time.zone.link.nonmembers] <https://wg21.link/time.zone.link.nonmembers>`_","| chrono::time_zone
| chrono::leap_second
| chrono::time_zone_link",None,Unassigned,|Not Started|
| chrono::time_zone_link",A ``<chrono>`` implementation,Unassigned,|Not Started|
| `[fs.path.nonmember] <https://wg21.link/fs.path.nonmember>`_,| filesystem::path,None,Unassigned,|Not Started|
| `[fs.dir.entry.obs] <https://wg21.link/fs.dir.entry.obs>`_,| filesystem::directory_entry,None,Unassigned,|Not Started|
| `[re.submatch.op] <https://wg21.link/re.submatch.op>`_,| sub_match,None,Unassigned,|Not Started|
Expand Down
23 changes: 4 additions & 19 deletions libcxx/include/__chrono/month.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <__chrono/duration.h>
#include <__config>
#include <compare>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down Expand Up @@ -45,25 +46,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month& __lhs, const month& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const month& __lhs, const month& __rhs) noexcept
{ return !(__lhs == __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const month& __lhs, const month& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const month& __lhs, const month& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const month& __lhs, const month& __rhs) noexcept
{ return !(__rhs < __lhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const month& __lhs, const month& __rhs) noexcept
{ return !(__lhs < __rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
}

_LIBCPP_HIDE_FROM_ABI inline constexpr
month operator+ (const month& __lhs, const months& __rhs) noexcept
Expand Down
51 changes: 10 additions & 41 deletions libcxx/include/__chrono/monthday.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <__chrono/day.h>
#include <__chrono/month.h>
#include <__config>
#include <compare>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down Expand Up @@ -58,9 +59,11 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
return __c;
return __lhs.day() <=> __rhs.day();
}

_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day operator/(const month& __lhs, const day& __rhs) noexcept
Expand All @@ -82,25 +85,6 @@ _LIBCPP_HIDE_FROM_ABI constexpr
month_day operator/(const day& __lhs, int __rhs) noexcept
{ return month(__rhs) / __lhs; }


_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
{ return !(__rhs < __lhs);}

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
{ return !(__lhs < __rhs); }



class month_day_last {
private:
chrono::month __m;
Expand All @@ -115,25 +99,10 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __lhs.month() == __rhs.month(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return !(__lhs == __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __lhs.month() < __rhs.month(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return !(__rhs < __lhs);}

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return !(__lhs < __rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
return __lhs.month() <=> __rhs.month();
}

_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day_last operator/(const month& __lhs, last_spec) noexcept
Expand Down
23 changes: 4 additions & 19 deletions libcxx/include/__chrono/year.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <__chrono/duration.h>
#include <__config>
#include <compare>
#include <limits>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Expand Down Expand Up @@ -56,25 +57,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year& __lhs, const year& __rhs) noexcept
{ return !(__lhs == __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const year& __lhs, const year& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const year& __lhs, const year& __rhs) noexcept
{ return !(__rhs < __lhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const year& __lhs, const year& __rhs) noexcept
{ return !(__lhs < __rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept {
return static_cast<int>(__lhs) <=> static_cast<int>(__rhs);
}

_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator+ (const year& __lhs, const years& __rhs) noexcept
Expand Down
25 changes: 6 additions & 19 deletions libcxx/include/__chrono/year_month.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <__chrono/month.h>
#include <__chrono/year.h>
#include <__config>
#include <compare>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down Expand Up @@ -52,25 +53,11 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
{ return !(__lhs == __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
{ return !(__rhs < __lhs);}

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
{ return !(__lhs < __rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
return __lhs.month() <=> __rhs.month();
}

_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
Expand Down
32 changes: 8 additions & 24 deletions libcxx/include/__chrono/year_month_day.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <__chrono/year.h>
#include <__chrono/year_month.h>
#include <__config>
#include <compare>
#include <limits>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Expand Down Expand Up @@ -109,32 +110,15 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return !(__lhs == __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{
if (__lhs.year() < __rhs.year()) return true;
if (__lhs.year() > __rhs.year()) return false;
if (__lhs.month() < __rhs.month()) return true;
if (__lhs.month() > __rhs.month()) return false;
return __lhs.day() < __rhs.day();
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept {
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
return __c;
return __lhs.day() <=> __rhs.day();
}

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return !(__rhs < __lhs);}

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return !(__lhs < __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
Expand Down
52 changes: 10 additions & 42 deletions libcxx/include/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,8 @@ constexpr days operator-(const day& x, const day& y) noexcept;
// 25.8.4, class month // C++20
class month;
constexpr bool operator==(const month& x, const month& y) noexcept;
constexpr bool operator!=(const month& x, const month& y) noexcept;
constexpr bool operator< (const month& x, const month& y) noexcept;
constexpr bool operator> (const month& x, const month& y) noexcept;
constexpr bool operator<=(const month& x, const month& y) noexcept;
constexpr bool operator>=(const month& x, const month& y) noexcept;
constexpr strong_ordering operator<=>(const month& x, const month& y) noexcept;
constexpr month operator+(const month& x, const months& y) noexcept;
constexpr month operator+(const months& x, const month& y) noexcept;
constexpr month operator-(const month& x, const months& y) noexcept;
Expand All @@ -349,11 +346,8 @@ constexpr months operator-(const month& x, const month& y) noexcept;
// 25.8.5, class year // C++20
class year;
constexpr bool operator==(const year& x, const year& y) noexcept;
constexpr bool operator!=(const year& x, const year& y) noexcept;
constexpr bool operator< (const year& x, const year& y) noexcept;
constexpr bool operator> (const year& x, const year& y) noexcept;
constexpr bool operator<=(const year& x, const year& y) noexcept;
constexpr bool operator>=(const year& x, const year& y) noexcept;
constexpr strong_ordering operator<=>(const year& x, const year& y) noexcept;
constexpr year operator+(const year& x, const years& y) noexcept;
constexpr year operator+(const years& x, const year& y) noexcept;
constexpr year operator-(const year& x, const years& y) noexcept;
Expand Down Expand Up @@ -385,22 +379,14 @@ constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept
class month_day;
constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
constexpr bool operator!=(const month_day& x, const month_day& y) noexcept;
constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
constexpr bool operator> (const month_day& x, const month_day& y) noexcept;
constexpr bool operator<=(const month_day& x, const month_day& y) noexcept;
constexpr bool operator>=(const month_day& x, const month_day& y) noexcept;
constexpr strong_ordering operator<=>(const month_day& x, const month_day& y) noexcept;
// 25.8.10, class month_day_last // C++20
class month_day_last;
constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept;
constexpr strong_ordering operator<=>(const month_day_last& x, const month_day_last& y) noexcept;
// 25.8.11, class month_weekday // C++20
class month_weekday;
Expand All @@ -419,11 +405,7 @@ constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last&
class year_month;
constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
constexpr bool operator!=(const year_month& x, const year_month& y) noexcept;
constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
constexpr bool operator> (const year_month& x, const year_month& y) noexcept;
constexpr bool operator<=(const year_month& x, const year_month& y) noexcept;
constexpr bool operator>=(const year_month& x, const year_month& y) noexcept;
constexpr strong_ordering operator<=>(const year_month& x, const year_month& y) noexcept;
constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
Expand All @@ -437,11 +419,7 @@ constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
year_month_day;
constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept;
constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
Expand All @@ -454,18 +432,8 @@ constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) n
// 25.8.15, class year_month_day_last // C++20
class year_month_day_last;
constexpr bool operator==(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator!=(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator< (const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator> (const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator<=(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator>=(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
constexpr strong_ordering operator<=>(const year_month_day_last_day& x, const year_month_day_last_day& y) noexcept;
constexpr year_month_day_last
operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
Expand Down
Loading

0 comments on commit 41f7bb9

Please sign in to comment.