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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
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>
34void 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 comparator
50 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
67void test() {
68 test_one<std::vector<int>>();
69 test_one<std::deque<int>>();
70 test_one<MinSequenceContainer<int>>();
71 test_one<std::vector<int, min_allocator<int>>>();
72
73 {
74 using C = std::flat_multiset<double>;
75 C s1 = {1};
76 C s2 = C(std::sorted_equivalent, {std::numeric_limits<double>::quiet_NaN()});
77 ASSERT_SAME_TYPE(decltype(s1 <=> s2), std::partial_ordering);
78 AssertComparisonsReturnBool<C>();
79 assert(testComparisonsComplete(s1, s2, false, false, false));
80 }
81 {
82 // Comparisons use value_type's native operators, not the comparator
83 struct StrongComp {
84 bool operator()(double a, double b) const { return std::strong_order(a, b) < 0; }
85 };
86 using C = std::flat_multiset<double, StrongComp>;
87 C s1 = {1};
88 C s2 = {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};
89 ASSERT_SAME_TYPE(decltype(s1 <=> s2), std::partial_ordering);
90 AssertComparisonsReturnBool<C>();
91 assert(testComparisonsComplete(s1, s2, false, false, false));
92 s1 = {1, std::numeric_limits<double>::quiet_NaN(), 1};
93 s2 = {1, std::numeric_limits<double>::quiet_NaN(), 1};
94 assert(std::lexicographical_compare_three_way(s1.begin(), s1.end(), s2.begin(), s2.end(), std::strong_order) ==
95 std::strong_ordering::equal);
96 assert(s1 != s2);
97 assert((s1 <=> s2) == std::partial_ordering::unordered);
98 }
99}
100
101int main(int, char**) {
102 test();
103
104 return 0;
105}
106

source code of libcxx/test/std/containers/container.adaptors/flat.multiset/op_compare.pass.cpp