[libcxx-commits] [libcxx] 41f7bb9 - [libc++][chrono] Uses operator<=> in the calendar.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 27 12:53:14 PDT 2022
Author: Mark de Wever
Date: 2022-07-27T21:53:08+02:00
New Revision: 41f7bb9975bcaffae0267fa87b63c90b83ffd551
URL: https://github.com/llvm/llvm-project/commit/41f7bb9975bcaffae0267fa87b63c90b83ffd551
DIFF: https://github.com/llvm/llvm-project/commit/41f7bb9975bcaffae0267fa87b63c90b83ffd551.diff
LOG: [libc++][chrono] Uses operator<=> in the calendar.
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
Added:
Modified:
libcxx/docs/Status/SpaceshipProjects.csv
libcxx/include/__chrono/month.h
libcxx/include/__chrono/monthday.h
libcxx/include/__chrono/year.h
libcxx/include/__chrono/year_month.h
libcxx/include/__chrono/year_month_day.h
libcxx/include/chrono
libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp
libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp
libcxx/test/std/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp
libcxx/test/std/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp
libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index 25bb7d0779015..9310388ab984e 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -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|
diff --git a/libcxx/include/__chrono/month.h b/libcxx/include/__chrono/month.h
index 5aeb5b3971824..b3e2d69288266 100644
--- a/libcxx/include/__chrono/month.h
+++ b/libcxx/include/__chrono/month.h
@@ -12,6 +12,7 @@
#include <__chrono/duration.h>
#include <__config>
+#include <compare>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -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
diff --git a/libcxx/include/__chrono/monthday.h b/libcxx/include/__chrono/monthday.h
index 485f0d4299b55..dec1d6bfdbfb0 100644
--- a/libcxx/include/__chrono/monthday.h
+++ b/libcxx/include/__chrono/monthday.h
@@ -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
@@ -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
@@ -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;
@@ -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
diff --git a/libcxx/include/__chrono/year.h b/libcxx/include/__chrono/year.h
index c7f0027eba7b4..425c08ba49607 100644
--- a/libcxx/include/__chrono/year.h
+++ b/libcxx/include/__chrono/year.h
@@ -12,6 +12,7 @@
#include <__chrono/duration.h>
#include <__config>
+#include <compare>
#include <limits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -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
diff --git a/libcxx/include/__chrono/year_month.h b/libcxx/include/__chrono/year_month.h
index 51b19caa11245..422d24fbf9867 100644
--- a/libcxx/include/__chrono/year_month.h
+++ b/libcxx/include/__chrono/year_month.h
@@ -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
@@ -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
diff --git a/libcxx/include/__chrono/year_month_day.h b/libcxx/include/__chrono/year_month_day.h
index 957716aab690b..9c7b1a42f23b1 100644
--- a/libcxx/include/__chrono/year_month_day.h
+++ b/libcxx/include/__chrono/year_month_day.h
@@ -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)
@@ -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}; }
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 2af5fbcc51651..209606929a649 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
diff --git a/libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp
index b284fc3c9c649..1fc7959d23be2 100644
--- a/libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.md/time.cal.md.nonmembers/comparisons.pass.cpp
@@ -11,13 +11,7 @@
// class month_day;
// constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
-// Returns: x.month() == y.month() && x.day() == y.day().
-//
-// constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
-// Returns:
-// If x.month() < y.month() returns true.
-// Otherwise, if x.month() > y.month() returns false.
-// Otherwise, returns x.day() < y.day().
+// constexpr strong_comparison operator<=>(const month_day& x, const month_day& y) noexcept;
#include <chrono>
#include <type_traits>
@@ -26,46 +20,50 @@
#include "test_macros.h"
#include "test_comparisons.h"
-int main(int, char**)
-{
- using day = std::chrono::day;
- using month = std::chrono::month;
- using month_day = std::chrono::month_day;
+constexpr bool test() {
+ using day = std::chrono::day;
+ using month = std::chrono::month;
+ using month_day = std::chrono::month_day;
+
+ assert(testOrder(
+ month_day{std::chrono::January, day{1}}, month_day{std::chrono::January, day{1}}, std::strong_ordering::equal));
- AssertComparisonsAreNoexcept<month_day>();
- AssertComparisonsReturnBool<month_day>();
+ assert(testOrder(
+ month_day{std::chrono::January, day{1}}, month_day{std::chrono::January, day{2}}, std::strong_ordering::less));
- static_assert( testComparisons(
- month_day{std::chrono::January, day{1}},
- month_day{std::chrono::January, day{1}},
- true, false), "");
+ assert(testOrder(
+ month_day{std::chrono::January, day{1}}, month_day{std::chrono::February, day{1}}, std::strong_ordering::less));
- static_assert( testComparisons(
- month_day{std::chrono::January, day{1}},
- month_day{std::chrono::January, day{2}},
- false, true), "");
+ // same day,
diff erent months
+ for (unsigned i = 1; i < 12; ++i)
+ for (unsigned j = 1; j < 12; ++j)
+ assert((testOrder(
+ month_day{month{i}, day{1}},
+ month_day{month{j}, day{1}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
- static_assert( testComparisons(
- month_day{std::chrono::January, day{1}},
- month_day{std::chrono::February, day{1}},
- false, true), "");
+ // same month,
diff erent days
+ for (unsigned i = 1; i < 31; ++i)
+ for (unsigned j = 1; j < 31; ++j)
+ assert((testOrder(
+ month_day{month{2}, day{i}},
+ month_day{month{2}, day{j}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
- // same day,
diff erent months
- for (unsigned i = 1; i < 12; ++i)
- for (unsigned j = 1; j < 12; ++j)
- assert((testComparisons(
- month_day{month{i}, day{1}},
- month_day{month{j}, day{1}},
- i == j, i < j )));
+ return true;
+}
- // same month,
diff erent days
- for (unsigned i = 1; i < 31; ++i)
- for (unsigned j = 1; j < 31; ++j)
- assert((testComparisons(
- month_day{month{2}, day{i}},
- month_day{month{2}, day{j}},
- i == j, i < j )));
+int main(int, char**) {
+ using month_day = std::chrono::month_day;
+ AssertOrderAreNoexcept<month_day>();
+ AssertOrderReturn<std::strong_ordering, month_day>();
+ test();
+ static_assert(test());
return 0;
}
diff --git a/libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp
index 8262b9194c988..59570084c352d 100644
--- a/libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.month/time.cal.month.nonmembers/comparisons.pass.cpp
@@ -11,12 +11,7 @@
// 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;
#include <chrono>
#include <type_traits>
@@ -25,24 +20,30 @@
#include "test_macros.h"
#include "test_comparisons.h"
+constexpr bool test() {
+ using month = std::chrono::month;
-int main(int, char**)
-{
- using month = std::chrono::month;
+ // Validate invalid values. The range [0, 255] is guaranteed to be allowed.
+ assert(testOrderValues<month>(0U, 0U));
+ assert(testOrderValues<month>(0U, 1U));
+ assert(testOrderValues<month>(254U, 255U));
+ assert(testOrderValues<month>(255U, 255U));
- AssertComparisonsAreNoexcept<month>();
- AssertComparisonsReturnBool<month>();
+ // Validate some valid values.
+ for (unsigned i = 1; i <= 12; ++i)
+ for (unsigned j = 1; j <= 12; ++j)
+ assert(testOrderValues<month>(i, j));
- static_assert(testComparisonsValues<month>(0U ,0U), "");
- static_assert(testComparisonsValues<month>(0U, 1U), "");
+ return true;
+}
- // Some 'ok' values as well
- static_assert(testComparisonsValues<month>( 5U, 5U), "");
- static_assert(testComparisonsValues<month>( 5U, 10U), "");
+int main(int, char**) {
+ using month = std::chrono::month;
+ AssertOrderAreNoexcept<month>();
+ AssertOrderReturn<std::strong_ordering, month>();
- for (unsigned i = 1; i <= 12; ++i)
- for (unsigned j = 1; j <= 12; ++j)
- assert(testComparisonsValues<month>(i, j));
+ test();
+ static_assert(test());
return 0;
}
diff --git a/libcxx/test/std/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp
index 8b05daeb1304f..497cc3a42e761 100644
--- a/libcxx/test/std/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.year/time.cal.year.nonmembers/comparisons.pass.cpp
@@ -11,12 +11,7 @@
// 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;
#include <chrono>
#include <type_traits>
@@ -25,24 +20,31 @@
#include "test_macros.h"
#include "test_comparisons.h"
+constexpr bool test() {
+ using year = std::chrono::year;
-int main(int, char**)
-{
- using year = std::chrono::year;
+ // Validate valid value. The range [-32768, 32767] is guaranteed to be allowed.
+ assert(testOrderValues<year>(-32768, -32768));
+ assert(testOrderValues<year>(-32768, -32767));
+ // Largest positive
+ assert(testOrderValues<year>(32767, 32766));
+ assert(testOrderValues<year>(32767, 32767));
- AssertComparisonsAreNoexcept<year>();
- AssertComparisonsReturnBool<year>();
+ // Validate some valid values.
+ for (int i = 1; i < 10; ++i)
+ for (int j = 1; j < 10; ++j)
+ assert(testOrderValues<year>(i, j));
- static_assert(testComparisonsValues<year>(0,0), "");
- static_assert(testComparisonsValues<year>(0,1), "");
+ return true;
+}
- // Some 'ok' values as well
- static_assert(testComparisonsValues<year>( 5, 5), "");
- static_assert(testComparisonsValues<year>( 5,10), "");
+int main(int, char**) {
+ using year = std::chrono::year;
+ AssertOrderAreNoexcept<year>();
+ AssertOrderReturn<std::strong_ordering, year>();
- for (int i = 1; i < 10; ++i)
- for (int j = 1; j < 10; ++j)
- assert(testComparisonsValues<year>(i, j));
+ test();
+ static_assert(test());
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp
index 4ff44688154e7..cafdfc91e5be8 100644
--- a/libcxx/test/std/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.ym/time.cal.ym.nonmembers/comparisons.pass.cpp
@@ -11,13 +11,7 @@
// class year_month;
// constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
-// Returns: x.year() == y.year() && x.month() == y.month().
-//
-// constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
-// Returns:
-// If x.year() < y.year() returns true.
-// Otherwise, if x.year() > y.year() returns false.
-// Otherwise, returns x.month() < y.month().
+// constexpr strong_order operator<=>(const year_month& x, const year_month& y) noexcept;
#include <chrono>
#include <type_traits>
@@ -26,45 +20,56 @@
#include "test_macros.h"
#include "test_comparisons.h"
-int main(int, char**)
-{
- using year = std::chrono::year;
- using month = std::chrono::month;
- using year_month = std::chrono::year_month;
+constexpr bool test() {
+ using year = std::chrono::year;
+ using month = std::chrono::month;
+ using year_month = std::chrono::year_month;
+
+ assert(testOrder(
+ year_month{year{1234}, std::chrono::January},
+ year_month{year{1234}, std::chrono::January},
+ std::strong_ordering::equal));
- AssertComparisonsAreNoexcept<year_month>();
- AssertComparisonsReturnBool<year_month>();
+ assert(testOrder(
+ year_month{year{1234}, std::chrono::January},
+ year_month{year{1234}, std::chrono::February},
+ std::strong_ordering::less));
- static_assert( testComparisons(
- year_month{year{1234}, std::chrono::January},
- year_month{year{1234}, std::chrono::January},
- true, false), "");
+ assert(testOrder(
+ year_month{year{1234}, std::chrono::January},
+ year_month{year{1235}, std::chrono::January},
+ std::strong_ordering::less));
- static_assert( testComparisons(
- year_month{year{1234}, std::chrono::January},
- year_month{year{1234}, std::chrono::February},
- false, true), "");
+ // same year,
diff erent months
+ for (unsigned i = 1; i < 12; ++i)
+ for (unsigned j = 1; j < 12; ++j)
+ assert((testOrder(
+ year_month{year{1234}, month{i}},
+ year_month{year{1234}, month{j}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
- static_assert( testComparisons(
- year_month{year{1234}, std::chrono::January},
- year_month{year{1235}, std::chrono::January},
- false, true), "");
+ // same month,
diff erent years
+ for (int i = -5; i < 5; ++i)
+ for (int j = -5; j < 5; ++j)
+ assert((testOrder(
+ year_month{year{i}, std::chrono::January},
+ year_month{year{j}, std::chrono::January},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
+
+ return true;
+}
- // same year,
diff erent months
- for (unsigned i = 1; i < 12; ++i)
- for (unsigned j = 1; j < 12; ++j)
- assert((testComparisons(
- year_month{year{1234}, month{i}},
- year_month{year{1234}, month{j}},
- i == j, i < j )));
+int main(int, char**) {
+ using year_month = std::chrono::year_month;
+ AssertOrderAreNoexcept<year_month>();
+ AssertOrderReturn<std::strong_ordering, year_month>();
- // same month,
diff erent years
- for (int i = 1000; i < 2000; ++i)
- for (int j = 1000; j < 2000; ++j)
- assert((testComparisons(
- year_month{year{i}, std::chrono::January},
- year_month{year{j}, std::chrono::January},
- i == j, i < j )));
+ test();
+ static_assert(test());
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp
index d8bca7a6fbf31..afc9f5d3d7666 100644
--- a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/comparisons.pass.cpp
@@ -11,16 +11,7 @@
// class year_month_day;
// constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
-// Returns: x.year() == y.year() && x.month() == y.month().
-//
-// constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
-// Returns:
-// If x.year() < y.year() returns true.
-// Otherwise, if x.year() > y.year() returns false.
-// Otherwise, if x.month() < y.month() returns true.
-// Otherwise, if x.month() > y.month() returns false.
-// Otherwise, returns x.day() < y.day()
-
+// constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
#include <chrono>
#include <type_traits>
@@ -29,91 +20,102 @@
#include "test_macros.h"
#include "test_comparisons.h"
-int main(int, char**)
-{
- using day = std::chrono::day;
- using year = std::chrono::year;
- using month = std::chrono::month;
- using year_month_day = std::chrono::year_month_day;
-
- AssertComparisonsAreNoexcept<year_month_day>();
- AssertComparisonsReturnBool<year_month_day>();
-
- constexpr month January = std::chrono::January;
- constexpr month February = std::chrono::February;
-
- static_assert( testComparisons(
- year_month_day{year{1234}, January, day{1}},
- year_month_day{year{1234}, January, day{1}},
- true, false), "");
-
- //
diff erent day
- static_assert( testComparisons(
- year_month_day{year{1234}, January, day{1}},
- year_month_day{year{1234}, January, day{2}},
- false, true), "");
-
- //
diff erent month
- static_assert( testComparisons(
- year_month_day{year{1234}, January, day{1}},
- year_month_day{year{1234}, February, day{1}},
- false, true), "");
-
- //
diff erent year
- static_assert( testComparisons(
- year_month_day{year{1234}, January, day{1}},
- year_month_day{year{1235}, January, day{1}},
- false, true), "");
-
-
- //
diff erent month and day
- static_assert( testComparisons(
- year_month_day{year{1234}, January, day{2}},
- year_month_day{year{1234}, February, day{1}},
- false, true), "");
-
- //
diff erent year and month
- static_assert( testComparisons(
- year_month_day{year{1234}, February, day{1}},
- year_month_day{year{1235}, January, day{1}},
- false, true), "");
-
- //
diff erent year and day
- static_assert( testComparisons(
- year_month_day{year{1234}, January, day{2}},
- year_month_day{year{1235}, January, day{1}},
- false, true), "");
-
- //
diff erent year, month and day
- static_assert( testComparisons(
- year_month_day{year{1234}, February, day{2}},
- year_month_day{year{1235}, January, day{1}},
- false, true), "");
-
-
- // same year,
diff erent days
- for (unsigned i = 1; i < 28; ++i)
- for (unsigned j = 1; j < 28; ++j)
- assert((testComparisons(
- year_month_day{year{1234}, January, day{i}},
- year_month_day{year{1234}, January, day{j}},
- i == j, i < j )));
-
- // same year,
diff erent months
- for (unsigned i = 1; i < 12; ++i)
- for (unsigned j = 1; j < 12; ++j)
- assert((testComparisons(
- year_month_day{year{1234}, month{i}, day{12}},
- year_month_day{year{1234}, month{j}, day{12}},
- i == j, i < j )));
-
- // same month,
diff erent years
- for (int i = 1000; i < 2000; ++i)
- for (int j = 1000; j < 2000; ++j)
- assert((testComparisons(
- year_month_day{year{i}, January, day{12}},
- year_month_day{year{j}, January, day{12}},
- i == j, i < j )));
-
- return 0;
+constexpr bool test() {
+ using day = std::chrono::day;
+ using year = std::chrono::year;
+ using month = std::chrono::month;
+ using year_month_day = std::chrono::year_month_day;
+
+ constexpr month January = std::chrono::January;
+ constexpr month February = std::chrono::February;
+
+ assert(testOrder(
+ year_month_day{year{1234}, January, day{1}},
+ year_month_day{year{1234}, January, day{1}},
+ std::strong_ordering::equal));
+
+ //
diff erent day
+ assert(testOrder(
+ year_month_day{year{1234}, January, day{1}},
+ year_month_day{year{1234}, January, day{2}},
+ std::strong_ordering::less));
+
+ //
diff erent month
+ assert(testOrder(
+ year_month_day{year{1234}, January, day{1}},
+ year_month_day{year{1234}, February, day{1}},
+ std::strong_ordering::less));
+
+ //
diff erent year
+ assert(testOrder(
+ year_month_day{year{1234}, January, day{1}},
+ year_month_day{year{1235}, January, day{1}},
+ std::strong_ordering::less));
+
+ //
diff erent month and day
+ assert(testOrder(
+ year_month_day{year{1234}, January, day{2}},
+ year_month_day{year{1234}, February, day{1}},
+ std::strong_ordering::less));
+
+ //
diff erent year and month
+ assert(testOrder(
+ year_month_day{year{1234}, February, day{1}},
+ year_month_day{year{1235}, January, day{1}},
+ std::strong_ordering::less));
+
+ //
diff erent year and day
+ assert(testOrder(
+ year_month_day{year{1234}, January, day{2}},
+ year_month_day{year{1235}, January, day{1}},
+ std::strong_ordering::less));
+
+ //
diff erent year, month and day
+ assert(testOrder(
+ year_month_day{year{1234}, February, day{2}},
+ year_month_day{year{1235}, January, day{1}},
+ std::strong_ordering::less));
+
+ // same year,
diff erent days
+ for (unsigned i = 1; i < 28; ++i)
+ for (unsigned j = 1; j < 28; ++j)
+ assert((testOrder(
+ year_month_day{year{1234}, January, day{i}},
+ year_month_day{year{1234}, January, day{j}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
+
+ // same year,
diff erent months
+ for (unsigned i = 1; i < 12; ++i)
+ for (unsigned j = 1; j < 12; ++j)
+ assert((testOrder(
+ year_month_day{year{1234}, month{i}, day{12}},
+ year_month_day{year{1234}, month{j}, day{12}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
+
+ // same month,
diff erent years
+ for (int i = -5; i < 5; ++i)
+ for (int j = -5; j < 5; ++j)
+ assert((testOrder(
+ year_month_day{year{i}, January, day{12}},
+ year_month_day{year{j}, January, day{12}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
+
+ return true;
+}
+
+int main(int, char**) {
+ using year_month_day = std::chrono::year_month_day;
+ AssertOrderAreNoexcept<year_month_day>();
+ AssertOrderReturn<std::strong_ordering, year_month_day>();
+
+ test();
+ static_assert(test());
+
+ return 0;
}
More information about the libcxx-commits
mailing list