Skip to content

Commit

Permalink
[libc++][NFC] Rename helper function for testing spaceship
Browse files Browse the repository at this point in the history
The helper is mis-named, since it won't work as-is on ordered containers
like set and map, because they rely on being able to store keys that are
partial_ordering::unordered, and that's UB for an ordered container.

This was most likely a typo or an unintended naming mistake, since
the function is only used with sequence containers anyway.

Differential Revision: https://reviews.llvm.org/D146991
  • Loading branch information
ldionne committed Mar 28, 2023
1 parent c2a4238 commit 177cb10
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Expand Up @@ -19,7 +19,7 @@
#include "test_container_comparisons.h"

int main(int, char**) {
assert(test_ordered_container_spaceship<std::deque>());
assert(test_sequence_container_spaceship<std::deque>());
// `std::deque` is not constexpr, so no `static_assert` test here.
return 0;
}
Expand Up @@ -19,7 +19,7 @@
#include "test_container_comparisons.h"

int main(int, char**) {
assert(test_ordered_container_spaceship<std::forward_list>());
assert(test_sequence_container_spaceship<std::forward_list>());
// `std::forward_list` is not constexpr, so no `static_assert` test here.
return 0;
}
Expand Up @@ -19,7 +19,7 @@
#include "test_container_comparisons.h"

int main(int, char**) {
assert(test_ordered_container_spaceship<std::list>());
assert(test_sequence_container_spaceship<std::list>());
// `std::list` is not constexpr, so no `static_assert` test here.
return 0;
}
18 changes: 9 additions & 9 deletions libcxx/test/support/test_container_comparisons.h
Expand Up @@ -12,9 +12,9 @@

#include "test_comparisons.h"

// Implementation detail of `test_ordered_container_spaceship`
// Implementation detail of `test_sequence_container_spaceship`
template <template <typename...> typename Container, typename Elem, typename Order>
constexpr void test_ordered_container_spaceship_with_type() {
constexpr void test_sequence_container_spaceship_with_type() {
// Empty containers
{
Container<Elem> l1;
Expand Down Expand Up @@ -59,20 +59,20 @@ constexpr void test_ordered_container_spaceship_with_type() {
}
}

// Tests the `operator<=>` on ordered containers
// Tests the `operator<=>` on sequence containers
template <template <typename...> typename Container>
constexpr bool test_ordered_container_spaceship() {
constexpr bool test_sequence_container_spaceship() {
// The container should fulfil `std::three_way_comparable`
static_assert(std::three_way_comparable<Container<int>>);

// Test different comparison categories
test_ordered_container_spaceship_with_type<Container, int, std::strong_ordering>();
test_ordered_container_spaceship_with_type<Container, StrongOrder, std::strong_ordering>();
test_ordered_container_spaceship_with_type<Container, WeakOrder, std::weak_ordering>();
test_ordered_container_spaceship_with_type<Container, PartialOrder, std::partial_ordering>();
test_sequence_container_spaceship_with_type<Container, int, std::strong_ordering>();
test_sequence_container_spaceship_with_type<Container, StrongOrder, std::strong_ordering>();
test_sequence_container_spaceship_with_type<Container, WeakOrder, std::weak_ordering>();
test_sequence_container_spaceship_with_type<Container, PartialOrder, std::partial_ordering>();

// `LessAndEqComp` does not have `operator<=>`. ordering is sythesized based on `operator<`
test_ordered_container_spaceship_with_type<Container, LessAndEqComp, std::weak_ordering>();
test_sequence_container_spaceship_with_type<Container, LessAndEqComp, std::weak_ordering>();

// Thanks to SFINAE, the following is not a compiler error but returns `false`
struct NonComparable {};
Expand Down

0 comments on commit 177cb10

Please sign in to comment.