-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++][functional] P2944R3 (partial): Comparisons for reference_wrapper
(reference_wrapper
operators only)
#88384
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
Merged
Zingam
merged 22 commits into
llvm:main
from
H-G-Hristov:hgh/libcxx/P2944R2-Comparisons-for-reference_wrapper
May 9, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d402314
[libc++][functional] P2944R3 (partial): Comparisons for ``reference_w…
H-G-Hristov 1f22a33
Tests: operator== WIP
H-G-Hristov ca199a8
Test: operator<=?> WIP
H-G-Hristov 24dc20b
Implemented https://wg21.link/LWG4071
H-G-Hristov f100fa2
Fixed includes
H-G-Hristov 6254165
Tests: WIP SFINAE `operator==`
H-G-Hristov fc10604
Tests: WIP SFINAE `operator<=>`
H-G-Hristov 288bbc0
Fixed formatting
H-G-Hristov a76111b
Tests: WIP `operator<=>`
H-G-Hristov 6ced2a0
Tests: WIP `operator<=>`
H-G-Hristov a611205
Tests: `operator==`
H-G-Hristov 60a4631
Tests: SFINAE `operator==`
H-G-Hristov 096e8ac
Merge branch 'main' into hgh/libcxx/P2944R2-Comparisons-for-reference…
H-G-Hristov eb0e7a9
Tests: `operator<=>`
H-G-Hristov 13c345d
Addressed some review comments
H-G-Hristov f910534
Merge branch 'main' into hgh/libcxx/P2944R2-Comparisons-for-reference…
H-G-Hristov 532c6d6
Split tests: one test per overload
H-G-Hristov 9f88c1f
Merge branch 'main' into hgh/libcxx/P2944R2-Comparisons-for-reference…
H-G-Hristov 780c0f9
Merge branch 'main' into hgh/libcxx/P2944R2-Comparisons-for-reference…
H-G-Hristov 3f2d3f7
Addressed some review comments
H-G-Hristov 9c72dab
Addressed review comments
H-G-Hristov 38eed6d
Merge branch 'main' into hgh/libcxx/P2944R2-Comparisons-for-reference…
H-G-Hristov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
89 changes: 89 additions & 0 deletions
89
...unction.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 | ||
|
||
// <functional> | ||
|
||
// class reference_wrapper | ||
|
||
// [refwrap.comparisons], comparisons | ||
|
||
// friend constexpr auto operator<=>(reference_wrapper, const T&); // Since C++26 | ||
|
||
#include <cassert> | ||
#include <concepts> | ||
#include <functional> | ||
|
||
#include "test_comparisons.h" | ||
#include "test_macros.h" | ||
|
||
#include "helper_concepts.h" | ||
#include "helper_types.h" | ||
|
||
// Test SFINAE. | ||
|
||
static_assert(HasSpaceshipOperatorWithInt<std::reference_wrapper<StrongOrder>>); | ||
static_assert(HasSpaceshipOperatorWithInt<std::reference_wrapper<WeakOrder>>); | ||
static_assert(HasSpaceshipOperatorWithInt<std::reference_wrapper<PartialOrder>>); | ||
|
||
static_assert(!HasSpaceshipOperatorWithInt<std::reference_wrapper<NonComparable>>); | ||
|
||
// Test comparisons. | ||
|
||
template <typename T, typename Order> | ||
constexpr void test() { | ||
T t{47}; | ||
|
||
T bigger{94}; | ||
T smaller{82}; | ||
|
||
T unordered{std::numeric_limits<int>::min()}; | ||
|
||
// Identical contents | ||
{ | ||
std::reference_wrapper<T> rw1{t}; | ||
assert(testOrder(rw1, t, Order::equivalent)); | ||
} | ||
// Less | ||
{ | ||
std::reference_wrapper<T> rw1{smaller}; | ||
assert(testOrder(rw1, bigger, Order::less)); | ||
} | ||
// Greater | ||
{ | ||
std::reference_wrapper<T> rw1{bigger}; | ||
assert(testOrder(rw1, smaller, Order::greater)); | ||
} | ||
// Unordered | ||
if constexpr (std::same_as<T, PartialOrder>) { | ||
std::reference_wrapper<T> rw1{bigger}; | ||
assert(testOrder(rw1, unordered, Order::unordered)); | ||
} | ||
} | ||
|
||
constexpr bool test() { | ||
test<int, std::strong_ordering>(); | ||
test<StrongOrder, std::strong_ordering>(); | ||
test<int, std::weak_ordering>(); | ||
test<WeakOrder, std::weak_ordering>(); | ||
test<int, std::partial_ordering>(); | ||
test<PartialOrder, std::partial_ordering>(); | ||
|
||
// `LessAndEqComp` does not have `operator<=>`. Ordering is synthesized based on `operator<` | ||
test<LessAndEqComp, std::weak_ordering>(); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
static_assert(test()); | ||
|
||
return 0; | ||
} |
93 changes: 93 additions & 0 deletions
93
.../function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 | ||
|
||
// <functional> | ||
|
||
// class reference_wrapper | ||
|
||
// [refwrap.comparisons], comparisons | ||
|
||
// friend constexpr auto operator<=>(reference_wrapper, reference_wrapper); // Since C++26 | ||
|
||
#include <cassert> | ||
#include <concepts> | ||
#include <functional> | ||
|
||
#include "test_comparisons.h" | ||
#include "test_macros.h" | ||
|
||
#include "helper_concepts.h" | ||
#include "helper_types.h" | ||
|
||
// Test SFINAE. | ||
|
||
static_assert(std::three_way_comparable<std::reference_wrapper<StrongOrder>>); | ||
static_assert(std::three_way_comparable<std::reference_wrapper<WeakOrder>>); | ||
static_assert(std::three_way_comparable<std::reference_wrapper<PartialOrder>>); | ||
|
||
static_assert(!std::three_way_comparable<std::reference_wrapper<NonComparable>>); | ||
|
||
// Test comparisons. | ||
|
||
template <typename T, typename Order> | ||
constexpr void test() { | ||
T t{47}; | ||
|
||
T bigger{94}; | ||
T smaller{82}; | ||
|
||
T unordered{std::numeric_limits<int>::min()}; | ||
|
||
// Identical contents | ||
{ | ||
std::reference_wrapper<T> rw1{t}; | ||
std::reference_wrapper<T> rw2{t}; | ||
assert(testOrder(rw1, rw2, Order::equivalent)); | ||
} | ||
// Less | ||
{ | ||
std::reference_wrapper<T> rw1{smaller}; | ||
std::reference_wrapper<T> rw2{bigger}; | ||
assert(testOrder(rw1, rw2, Order::less)); | ||
} | ||
// Greater | ||
{ | ||
std::reference_wrapper<T> rw1{bigger}; | ||
std::reference_wrapper<T> rw2{smaller}; | ||
assert(testOrder(rw1, rw2, Order::greater)); | ||
} | ||
// Unordered | ||
if constexpr (std::same_as<T, PartialOrder>) { | ||
std::reference_wrapper<T> rw1{bigger}; | ||
std::reference_wrapper<T> rw2{unordered}; | ||
assert(testOrder(rw1, rw2, Order::unordered)); | ||
} | ||
} | ||
|
||
constexpr bool test() { | ||
test<int, std::strong_ordering>(); | ||
test<StrongOrder, std::strong_ordering>(); | ||
test<int, std::weak_ordering>(); | ||
test<WeakOrder, std::weak_ordering>(); | ||
test<int, std::partial_ordering>(); | ||
test<PartialOrder, std::partial_ordering>(); | ||
|
||
// `LessAndEqComp` does not have `operator<=>`. Ordering is synthesized based on `operator<` | ||
test<LessAndEqComp, std::weak_ordering>(); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
static_assert(test()); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.