brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 606cdfc Raw
114 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 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_set>12 13// friend bool operator==(const flat_multiset& x, const flat_multiset& y);14// friend synth-three-way-result<value_type>15//   operator<=>(const flat_multiset& x, const flat_multiset& y);16 17#include <algorithm>18#include <cassert>19#include <deque>20#include <compare>21#include <flat_set>22#include <functional>23#include <limits>24#include <vector>25 26#include "MinSequenceContainer.h"27#include "test_macros.h"28#include "min_allocator.h"29#include "test_allocator.h"30#include "test_comparisons.h"31#include "test_container_comparisons.h"32 33template <class KeyContainer>34constexpr void test_one() {35  using Key = typename KeyContainer::value_type;36 37  {38    using C = std::flat_multiset<Key>;39    C s1, s2;40    ASSERT_SAME_TYPE(decltype(s1 <=> s2), std::strong_ordering);41    AssertComparisonsReturnBool<C>();42    assert(testComparisons(C{1, 1, 2}, C{1, 1, 3}, false, true));43    assert(testComparisons(C{1, 1}, C{1, 1}, true, false));44    assert(testComparisons(C{1, 10}, C{2, 2}, false, true));45    assert(testComparisons(C{}, C{1}, false, true));46    assert(testComparisons(C{2}, C{1, 1, 1, 1, 1}, false, false));47  }48  {49    // Comparisons use value_type's native operators, not the comparator50    using C = std::flat_multiset<Key, std::greater<Key>>;51    C s1    = {1, 1};52    C s2    = {2, 2};53    ASSERT_SAME_TYPE(decltype(s1 <=> s2), std::strong_ordering);54    AssertComparisonsReturnBool<C>();55    assert(testComparisons(s1, s2, false, true));56    s2 = {1, 1};57    assert(testComparisons(s1, s2, true, false));58    s2 = {1, 2};59    assert(testComparisons(s1, s2, false, true));60    s1 = {0, 1, 2};61    assert(testComparisons(s1, s2, false, false));62    s2 = {0, 1, 3};63    assert(testComparisons(s1, s2, false, true));64  }65}66 67constexpr bool test() {68  test_one<std::vector<int>>();69#ifndef __cpp_lib_constexpr_deque70  if (!TEST_IS_CONSTANT_EVALUATED)71#endif72    test_one<std::deque<int>>();73  test_one<MinSequenceContainer<int>>();74  test_one<std::vector<int, min_allocator<int>>>();75 76  {77    using C = std::flat_multiset<double>;78    C s1    = {1};79    C s2    = C(std::sorted_equivalent, {std::numeric_limits<double>::quiet_NaN()});80    ASSERT_SAME_TYPE(decltype(s1 <=> s2), std::partial_ordering);81    AssertComparisonsReturnBool<C>();82    assert(testComparisonsComplete(s1, s2, false, false, false));83  }84  {85    // Comparisons use value_type's native operators, not the comparator86    struct StrongComp {87      constexpr bool operator()(double a, double b) const { return std::strong_order(a, b) < 0; }88    };89    using C = std::flat_multiset<double, StrongComp>;90    C s1    = {1};91    C s2    = {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};92    ASSERT_SAME_TYPE(decltype(s1 <=> s2), std::partial_ordering);93    AssertComparisonsReturnBool<C>();94    assert(testComparisonsComplete(s1, s2, false, false, false));95    s1 = {1, std::numeric_limits<double>::quiet_NaN(), 1};96    s2 = {1, std::numeric_limits<double>::quiet_NaN(), 1};97    assert(std::lexicographical_compare_three_way(s1.begin(), s1.end(), s2.begin(), s2.end(), std::strong_order) ==98           std::strong_ordering::equal);99    assert(s1 != s2);100    assert((s1 <=> s2) == std::partial_ordering::unordered);101  }102 103  return true;104}105 106int main(int, char**) {107  test();108#if TEST_STD_VER >= 26109  static_assert(test());110#endif111 112  return 0;113}114