brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 671747f Raw
87 lines · cpp
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <array>11 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);15 16#include <array>17#include <cassert>18 19#include "test_comparisons.h"20 21// SFINAE22 23constexpr std::size_t N{1};24 25// The container should fulfill `std::three_way_comparable`26static_assert(std::three_way_comparable<std::array<int, N>>);27 28// Thanks to SFINAE, the following is not a compiler error but returns `false`29static_assert(!std::three_way_comparable<std::array<NonComparable, N>>);30 31// Implementation detail of `test_sequence_container_array_spaceship`32template <typename Elem, typename Order>33constexpr void test_sequence_container_array_spaceship_with_type() {34  // Empty containers35  {36    std::array<Elem, 0> l1 = {};37    std::array<Elem, 0> l2 = {};38    assert(testOrder(l1, l2, Order::equivalent));39  }40  // Identical contents41  {42    std::array l1{Elem{1}, Elem{1}};43    std::array l2{Elem{1}, Elem{1}};44    assert(testOrder(l1, l2, Order::equivalent));45  }46  // Less, due to contained values47  {48    std::array l1{Elem{1}, Elem{1}};49    std::array l2{Elem{1}, Elem{2}};50    assert(testOrder(l1, l2, Order::less));51  }52  // Greater, due to contained values53  {54    std::array l1{Elem{1}, Elem{3}};55    std::array l2{Elem{1}, Elem{2}};56    assert(testOrder(l1, l2, Order::greater));57  }58  // Shorter list - unsupported - containers must be of equal lengths59  // Longer list - unsupported - containers must be of equal lengths60  // Unordered61  if constexpr (std::is_same_v<Elem, PartialOrder>) {62    std::array l1{Elem{1}, Elem{std::numeric_limits<int>::min()}};63    std::array l2{Elem{1}, Elem{2}};64    assert(testOrder(l1, l2, Order::unordered));65  }66}67 68// Tests the `operator<=>` on sequence containers `array`69constexpr bool test_sequence_container_array_spaceship() {70  // Test different comparison categories71  test_sequence_container_array_spaceship_with_type<int, std::strong_ordering>();72  test_sequence_container_array_spaceship_with_type<StrongOrder, std::strong_ordering>();73  test_sequence_container_array_spaceship_with_type<WeakOrder, std::weak_ordering>();74  test_sequence_container_array_spaceship_with_type<PartialOrder, std::partial_ordering>();75 76  // `LessAndEqComp` does not have `operator<=>`. Ordering is synthesized based on `operator<`77  test_sequence_container_array_spaceship_with_type<LessAndEqComp, std::weak_ordering>();78 79  return true;80}81 82int main(int, char**) {83  assert(test_sequence_container_array_spaceship());84  static_assert(test_sequence_container_array_spaceship());85  return 0;86}87