diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv --- a/libcxx/docs/Status/SpaceshipProjects.csv +++ b/libcxx/docs/Status/SpaceshipProjects.csv @@ -51,31 +51,28 @@ | `[range.iota.iterator] `_,| ranges::iota_view::iterator,[concepts.cmp],Unassigned,|Not Started| | `[range.transform.iterator] `_,| ranges::transform_view::iterator,[concepts.cmp],Unassigned,|Not Started| | `[range.elements.iterator] `_,| ranges::elements_view::iterator,[concepts.cmp],Unassigned,|Not Started| -"| `[time.duration.comparisons] `_ -| `[time.point.comparisons] `_ -| `[time.cal.day.nonmembers] `_ +| `[time.duration.comparisons] `_, "chrono::duration", None, Mark de Wever, |Not Started| +| `[time.point.comparisons] `_, "chrono::point", None, Mark de Wever, |Not Started| +"| `[time.cal.day.nonmembers] `_ | `[time.cal.month.nonmembers] `_ | `[time.cal.year.nonmembers] `_ | `[time.cal.md.nonmembers] `_ | `[time.cal.mdlast] `_ | `[time.cal.ym.nonmembers] `_ | `[time.cal.ymd.nonmembers] `_ -| `[time.cal.ymdlast.nonmembers] `_ -| `[time.zone.nonmembers] `_ -| `[time.zone.leap.nonmembers] `_ -| `[time.zone.link.nonmembers] `_","| chrono::duration -| chrono::time_point -| chrono::day +| `[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] `_ +| `[time.zone.leap.nonmembers] `_ +| `[time.zone.link.nonmembers] `_","| chrono::time_zone | chrono::leap_second -| chrono::time_zone_link",None,Unassigned,|Not Started| +| chrono::time_zone_link",A ```` implementation,Unassigned,|Not Started| | `[fs.path.nonmember] `_,| filesystem::path,None,Unassigned,|Not Started| | `[fs.dir.entry.obs] `_,| filesystem::directory_entry,None,Unassigned,|Not Started| | `[re.submatch.op] `_,| sub_match,None,Unassigned,|Not Started| diff --git a/libcxx/include/__chrono/month.h b/libcxx/include/__chrono/month.h --- a/libcxx/include/__chrono/month.h +++ b/libcxx/include/__chrono/month.h @@ -12,6 +12,7 @@ #include <__chrono/duration.h> #include <__config> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -45,25 +46,9 @@ bool operator==(const month& __lhs, const month& __rhs) noexcept { return static_cast(__lhs) == static_cast(__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(__lhs) < static_cast(__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(__lhs) <=> static_cast(__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 --- 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 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -58,9 +59,11 @@ 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 @@ 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 @@ 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 --- a/libcxx/include/__chrono/year.h +++ b/libcxx/include/__chrono/year.h @@ -12,6 +12,7 @@ #include <__chrono/duration.h> #include <__config> +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -56,25 +57,9 @@ bool operator==(const year& __lhs, const year& __rhs) noexcept { return static_cast(__lhs) == static_cast(__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(__lhs) < static_cast(__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(__lhs) <=> static_cast(__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 --- 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 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -52,6 +53,12 @@ bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } +_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 inline constexpr bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept { return !(__lhs == __rhs); } diff --git a/libcxx/include/__chrono/year_month_day.h b/libcxx/include/__chrono/year_month_day.h --- 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 #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -109,32 +110,15 @@ 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 --- a/libcxx/include/chrono +++ b/libcxx/include/chrono @@ -336,11 +336,8 @@ // 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 @@ // 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 @@ 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 @@ 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 @@ 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 @@ // 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 --- 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 #include @@ -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(); - AssertComparisonsReturnBool(); + 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, different 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, different 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, different 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, different 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(); + AssertOrderReturn(); + 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 --- 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 #include @@ -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(0U, 0U)); + assert(testOrderValues(0U, 1U)); + assert(testOrderValues(254U, 255U)); + assert(testOrderValues(255U, 255U)); - AssertComparisonsAreNoexcept(); - AssertComparisonsReturnBool(); + // Validate some valid values. + for (unsigned i = 1; i <= 12; ++i) + for (unsigned j = 1; j <= 12; ++j) + assert(testOrderValues(i, j)); - static_assert(testComparisonsValues(0U ,0U), ""); - static_assert(testComparisonsValues(0U, 1U), ""); + return true; +} - // Some 'ok' values as well - static_assert(testComparisonsValues( 5U, 5U), ""); - static_assert(testComparisonsValues( 5U, 10U), ""); +int main(int, char**) { + using month = std::chrono::month; + AssertOrderAreNoexcept(); + AssertOrderReturn(); - for (unsigned i = 1; i <= 12; ++i) - for (unsigned j = 1; j <= 12; ++j) - assert(testComparisonsValues(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 --- 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 #include @@ -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(-32768, -32768)); + assert(testOrderValues(-32768, -32767)); + // Largest positive + assert(testOrderValues(32767, 32766)); + assert(testOrderValues(32767, 32767)); - AssertComparisonsAreNoexcept(); - AssertComparisonsReturnBool(); + // Validate some valid values. + for (int i = 1; i < 10; ++i) + for (int j = 1; j < 10; ++j) + assert(testOrderValues(i, j)); - static_assert(testComparisonsValues(0,0), ""); - static_assert(testComparisonsValues(0,1), ""); + return true; +} - // Some 'ok' values as well - static_assert(testComparisonsValues( 5, 5), ""); - static_assert(testComparisonsValues( 5,10), ""); +int main(int, char**) { + using year = std::chrono::year; + AssertOrderAreNoexcept(); + AssertOrderReturn(); - for (int i = 1; i < 10; ++i) - for (int j = 1; j < 10; ++j) - assert(testComparisonsValues(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 --- 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 #include @@ -26,45 +20,61 @@ #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)); + + assert(testOrder( + year_month{year{1234}, std::chrono::January}, + year_month{year{1234}, std::chrono::February}, + std::strong_ordering::less)); - AssertComparisonsAreNoexcept(); - AssertComparisonsReturnBool(); + 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::January}, - true, false), ""); + // same year, different 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{1234}, std::chrono::February}, - false, true), ""); + // Use a maximum to avoid hitting the maximum number of constexpr steps. + // Another solution would be increment the number of step, but that leads to + // long compilation times. + int max = std::is_constant_evaluated() ? 1010 : 2000; - static_assert( testComparisons( - year_month{year{1234}, std::chrono::January}, - year_month{year{1235}, std::chrono::January}, - false, true), ""); + // same month, different years + for (int i = 1000; i < max; ++i) + for (int j = 1000; j < max; ++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, different 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(); + AssertOrderReturn(); - // same month, different 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 --- 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 #include @@ -29,91 +20,107 @@ #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(); - AssertComparisonsReturnBool(); - - 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), ""); - - // different day - static_assert( testComparisons( - year_month_day{year{1234}, January, day{1}}, - year_month_day{year{1234}, January, day{2}}, - false, true), ""); - - // different month - static_assert( testComparisons( - year_month_day{year{1234}, January, day{1}}, - year_month_day{year{1234}, February, day{1}}, - false, true), ""); - - // different year - static_assert( testComparisons( - year_month_day{year{1234}, January, day{1}}, - year_month_day{year{1235}, January, day{1}}, - false, true), ""); - - - // different month and day - static_assert( testComparisons( - year_month_day{year{1234}, January, day{2}}, - year_month_day{year{1234}, February, day{1}}, - false, true), ""); - - // different year and month - static_assert( testComparisons( - year_month_day{year{1234}, February, day{1}}, - year_month_day{year{1235}, January, day{1}}, - false, true), ""); - - // different year and day - static_assert( testComparisons( - year_month_day{year{1234}, January, day{2}}, - year_month_day{year{1235}, January, day{1}}, - false, true), ""); - - // different 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, different 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, different 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, different 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)); + + // different day + assert(testOrder( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1234}, January, day{2}}, + std::strong_ordering::less)); + + // different month + assert(testOrder( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1234}, February, day{1}}, + std::strong_ordering::less)); + + // different year + assert(testOrder( + year_month_day{year{1234}, January, day{1}}, + year_month_day{year{1235}, January, day{1}}, + std::strong_ordering::less)); + + // different 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)); + + // different 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)); + + // different 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)); + + // different 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, different 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, different 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))); + + // Use a maximum to avoid hitting the maximum number of constexpr steps. + // Another solution would be increment the number of step, but that leads to + // long compilation times. + int max = std::is_constant_evaluated() ? 1010 : 2000; + + // same month, different years + for (int i = 1000; i < max; ++i) + for (int j = 1000; j < max; ++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(); + AssertOrderReturn(); + + test(); + static_assert(test()); + + return 0; }