-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++][chrono] Adds year_month_day_last&::operator<=>. #98169
Merged
mordante
merged 1 commit into
llvm:main
from
mordante:review/finishes_chrono_calendar_spaceship
Jul 16, 2024
Merged
[libc++][chrono] Adds year_month_day_last&::operator<=>. #98169
mordante
merged 1 commit into
llvm:main
from
mordante:review/finishes_chrono_calendar_spaceship
Jul 16, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
the
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
label
Jul 9, 2024
@llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) Changes41f7bb9 claimed it implemented this change but the code was not adjusted. The other spaceship operators in the calendar code have been validated too. Implements parts of
Full diff: https://github.com/llvm/llvm-project/pull/98169.diff 2 Files Affected:
diff --git a/libcxx/include/__chrono/year_month_day.h b/libcxx/include/__chrono/year_month_day.h
index 75884f3654d87..b06c0be03e0de 100644
--- a/libcxx/include/__chrono/year_month_day.h
+++ b/libcxx/include/__chrono/year_month_day.h
@@ -239,33 +239,11 @@ operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) n
return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last();
}
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool
-operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
- return !(__lhs == __rhs);
-}
-
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool
-operator<(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
- if (__lhs.year() < __rhs.year())
- return true;
- if (__lhs.year() > __rhs.year())
- return false;
- return __lhs.month_day_last() < __rhs.month_day_last();
-}
-
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool
-operator>(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
- return __rhs < __lhs;
-}
-
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool
-operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
- return !(__rhs < __lhs);
-}
-
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool
-operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
- return !(__lhs < __rhs);
+_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
+operator<=>(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
+ if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
+ return __c;
+ return __lhs.month_day_last() <=> __rhs.month_day_last();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept {
diff --git a/libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp b/libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp
index 45d7e51fbe718..e28b6d8609bc4 100644
--- a/libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp
+++ b/libcxx/test/std/time/time.cal/time.cal.ymdlast/time.cal.ymdlast.nonmembers/comparisons.pass.cpp
@@ -5,19 +5,14 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
// <chrono>
// class year_month_day_last;
// constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
-// Returns: x.year() == y.year() && x.month_day_last() == y.month_day_last().
-//
-// constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept;
-// Returns:
-// If x.year() < y.year(), returns true.
-// Otherwise, if x.year() > y.year(), returns false.
-// Otherwise, returns x.month_day_last() < y.month_day_last()
+// constexpr bool operator<=>(const year_month_day_last& x, const year_month_day_last& y) noexcept;
#include <chrono>
#include <type_traits>
@@ -26,63 +21,61 @@
#include "test_macros.h"
#include "test_comparisons.h"
-int main(int, char**)
-{
- using year = std::chrono::year;
- using month = std::chrono::month;
- using month_day_last = std::chrono::month_day_last;
- using year_month_day_last = std::chrono::year_month_day_last;
-
- AssertComparisonsAreNoexcept<year_month_day_last>();
- AssertComparisonsReturnBool<year_month_day_last>();
-
- constexpr month January = std::chrono::January;
- constexpr month February = std::chrono::February;
-
- static_assert( testComparisons(
- year_month_day_last{year{1234}, month_day_last{January}},
- year_month_day_last{year{1234}, month_day_last{January}},
- true, false), "");
-
- // different month
- static_assert( testComparisons(
- year_month_day_last{year{1234}, month_day_last{January}},
- year_month_day_last{year{1234}, month_day_last{February}},
- false, true), "");
-
- // different year
- static_assert( testComparisons(
- year_month_day_last{year{1234}, month_day_last{January}},
- year_month_day_last{year{1235}, month_day_last{January}},
- false, true), "");
-
- // different month
- static_assert( testComparisons(
- year_month_day_last{year{1234}, month_day_last{January}},
- year_month_day_last{year{1234}, month_day_last{February}},
- false, true), "");
-
- // different year and month
- static_assert( testComparisons(
- year_month_day_last{year{1234}, month_day_last{February}},
- year_month_day_last{year{1235}, month_day_last{January}},
- false, true), "");
-
- // same year, different months
- for (unsigned i = 1; i < 12; ++i)
- for (unsigned j = 1; j < 12; ++j)
- assert((testComparisons(
- year_month_day_last{year{1234}, month_day_last{month{i}}},
- year_month_day_last{year{1234}, month_day_last{month{j}}},
- 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_last{year{i}, month_day_last{January}},
- year_month_day_last{year{j}, month_day_last{January}},
- i == j, i < j )));
-
- return 0;
+constexpr bool test() {
+ using year = std::chrono::year;
+ using month = std::chrono::month;
+ using month_day_last = std::chrono::month_day_last;
+ using year_month_day_last = std::chrono::year_month_day_last;
+
+ constexpr month January = std::chrono::January;
+ constexpr month February = std::chrono::February;
+
+ assert(testOrder(year_month_day_last{year{1234}, month_day_last{January}},
+ year_month_day_last{year{1234}, month_day_last{January}},
+ std::strong_ordering::equal));
+
+ // different month
+ assert(testOrder(year_month_day_last{year{1234}, month_day_last{January}},
+ year_month_day_last{year{1234}, month_day_last{February}},
+ std::strong_ordering::less));
+
+ // different year
+ assert(testOrder(year_month_day_last{year{1234}, month_day_last{January}},
+ year_month_day_last{year{1235}, month_day_last{January}},
+ std::strong_ordering::less));
+
+ // different year and month
+ assert(testOrder(year_month_day_last{year{1234}, month_day_last{February}},
+ year_month_day_last{year{1235}, month_day_last{January}},
+ std::strong_ordering::less));
+
+ // same year, different months
+ for (unsigned i = 1; i < 12; ++i)
+ for (unsigned j = 1; j < 12; ++j)
+ assert((testOrder(year_month_day_last{year{1234}, month_day_last{month{i}}},
+ year_month_day_last{year{1234}, month_day_last{month{j}}},
+ i == j ? std::strong_ordering::equal
+ : i < j ? std::strong_ordering::less
+ : std::strong_ordering::greater)));
+
+ // same month, different years
+ for (int i = 1000; i < 20; ++i)
+ for (int j = 1000; j < 20; ++j)
+ assert((testOrder(year_month_day_last{year{i}, month_day_last{January}},
+ year_month_day_last{year{j}, month_day_last{January}},
+ 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_last = std::chrono::year_month_day_last;
+ AssertOrderAreNoexcept<year_month_day_last>();
+ AssertOrderReturn<std::strong_ordering, year_month_day_last>();
+
+ test();
+ static_assert(test());
+
+ return 0;
}
|
41f7bb9 claimed it implemented this change but the code was not adjusted. The other spaceship operators in the calendar code have been validated too. Implements parts of - P1614R2 The Mothership has Landed
mordante
force-pushed
the
review/finishes_chrono_calendar_spaceship
branch
from
July 10, 2024 08:02
cd21c27
to
6d624bf
Compare
ldionne
approved these changes
Jul 15, 2024
sayhaan
pushed a commit
to sayhaan/llvm-project
that referenced
this pull request
Jul 16, 2024
Summary: 41f7bb9 claimed it implemented this change but the code was not adjusted. The other spaceship operators in the calendar code have been validated too. Implements parts of - P1614R2 The Mothership has Landed Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D59822456
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
41f7bb9 claimed it implemented this change but the code was not adjusted. The other spaceship operators in the calendar code have been validated too. Implements parts of - P1614R2 The Mothership has Landed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
41f7bb9 claimed it implemented this change but the code was not adjusted. The other spaceship operators in the calendar code have been validated too.
Implements parts of