1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // template<class T, size_t N>
13 // constexpr synth-three-way-result<T>
14 // operator<=>(const array<T, N>& x, const array<T, N>& y);
19 #include "test_comparisons.h"
23 constexpr std::size_t N
{1};
25 // The container should fulfill `std::three_way_comparable`
26 static_assert(std::three_way_comparable
<std::array
<int, N
>>);
28 // Thanks to SFINAE, the following is not a compiler error but returns `false`
29 struct NonComparable
{};
30 static_assert(!std::three_way_comparable
<std::array
<NonComparable
, N
>>);
32 // Implementation detail of `test_sequence_container_array_spaceship`
33 template <typename Elem
, typename Order
>
34 constexpr void test_sequence_container_array_spaceship_with_type() {
37 std::array
<Elem
, 0> l1
= {};
38 std::array
<Elem
, 0> l2
= {};
39 assert(testOrder(l1
, l2
, Order::equivalent
));
43 std::array l1
{Elem
{1}, Elem
{1}};
44 std::array l2
{Elem
{1}, Elem
{1}};
45 assert(testOrder(l1
, l2
, Order::equivalent
));
47 // Less, due to contained values
49 std::array l1
{Elem
{1}, Elem
{1}};
50 std::array l2
{Elem
{1}, Elem
{2}};
51 assert(testOrder(l1
, l2
, Order::less
));
53 // Greater, due to contained values
55 std::array l1
{Elem
{1}, Elem
{3}};
56 std::array l2
{Elem
{1}, Elem
{2}};
57 assert(testOrder(l1
, l2
, Order::greater
));
59 // Shorter list - unsupported - containers must be of equal lengths
60 // Longer list - unsupported - containers must be of equal lengths
62 if constexpr (std::is_same_v
<Elem
, PartialOrder
>) {
63 std::array l1
{Elem
{1}, Elem
{std::numeric_limits
<int>::min()}};
64 std::array l2
{Elem
{1}, Elem
{2}};
65 assert(testOrder(l1
, l2
, Order::unordered
));
69 // Tests the `operator<=>` on sequence containers `array`
70 constexpr bool test_sequence_container_array_spaceship() {
71 // Test different comparison categories
72 test_sequence_container_array_spaceship_with_type
<int, std::strong_ordering
>();
73 test_sequence_container_array_spaceship_with_type
<StrongOrder
, std::strong_ordering
>();
74 test_sequence_container_array_spaceship_with_type
<WeakOrder
, std::weak_ordering
>();
75 test_sequence_container_array_spaceship_with_type
<PartialOrder
, std::partial_ordering
>();
77 // `LessAndEqComp` does not have `operator<=>`. Ordering is synthesized based on `operator<`
78 test_sequence_container_array_spaceship_with_type
<LessAndEqComp
, std::weak_ordering
>();
83 int main(int, char**) {
84 assert(test_sequence_container_array_spaceship());
85 static_assert(test_sequence_container_array_spaceship());