+2020-04-20 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/bits/stl_map.h (map): Define operator<=> and remove
+ operator< for C++20.
+ * include/bits/stl_multimap.h (multimap): Likewise.
+ * include/bits/stl_multiset.h (multiset): Likewise.
+ * include/bits/stl_set.h (set): Likewise.
+ * include/bits/stl_tree.h (_Rb_tree): Likewise.
+ (_Rb_tree_iterator, _Rb_tree_const_iterator): Remove redundant
+ operator!= for C++20.
+ * include/debug/map.h (__gnu_debug::map): Define operator<=> for C++20.
+ * include/debug/multimap.h (__gnu_debug::multimap): Likewise.
+ * include/debug/multiset.h (__gnu_debug::multiset): Likewise.
+ * include/debug/set.h (__gnu_debug::set): Likewise.
+ * testsuite/23_containers/map/operators/cmp_c++20.cc: New test.
+ * testsuite/23_containers/multimap/operators/cmp_c++20.cc: New test.
+ * testsuite/23_containers/multiset/operators/cmp_c++20.cc: New test.
+ * testsuite/23_containers/set/operators/cmp_c++20.cc: New test.
+
2020-04-20 Matthias Kretz <kretz@kde.org>
* testsuite/lib/libstdc++.exp: Avoid illegal argument to verbose.
operator==(const map<_K1, _T1, _C1, _A1>&,
const map<_K1, _T1, _C1, _A1>&);
+#if __cpp_lib_three_way_comparison
+ template<typename _K1, typename _T1, typename _C1, typename _A1>
+ friend __detail::__synth3way_t<pair<const _K1, _T1>>
+ operator<=>(const map<_K1, _T1, _C1, _A1>&,
+ const map<_K1, _T1, _C1, _A1>&);
+#else
template<typename _K1, typename _T1, typename _C1, typename _A1>
friend bool
operator<(const map<_K1, _T1, _C1, _A1>&,
const map<_K1, _T1, _C1, _A1>&);
+#endif
};
map(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> map<_Key, _Tp, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
/**
* @brief Map equality comparison.
const map<_Key, _Tp, _Compare, _Alloc>& __y)
{ return __x._M_t == __y._M_t; }
+#if __cpp_lib_three_way_comparison
+ /**
+ * @brief Map ordering relation.
+ * @param __x A `map`.
+ * @param __y A `map` of the same type as `x`.
+ * @return A value indicating whether `__x` is less than, equal to,
+ * greater than, or incomparable with `__y`.
+ *
+ * This is a total ordering relation. It is linear in the size of the
+ * maps. The elements must be comparable with @c <.
+ *
+ * See `std::lexicographical_compare_three_way()` for how the determination
+ * is made. This operator is used to synthesize relational operators like
+ * `<` and `>=` etc.
+ */
+ template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<pair<const _Key, _Tp>>
+ operator<=>(const map<_Key, _Tp, _Compare, _Alloc>& __x,
+ const map<_Key, _Tp, _Compare, _Alloc>& __y)
+ { return __x._M_t <=> __y._M_t; }
+#else
/**
* @brief Map ordering relation.
* @param __x A %map.
operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
const map<_Key, _Tp, _Compare, _Alloc>& __y)
{ return !(__x < __y); }
+#endif // three-way comparison
/// See std::map::swap().
template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
operator==(const multimap<_K1, _T1, _C1, _A1>&,
const multimap<_K1, _T1, _C1, _A1>&);
+#if __cpp_lib_three_way_comparison
+ template<typename _K1, typename _T1, typename _C1, typename _A1>
+ friend __detail::__synth3way_t<pair<const _K1, _T1>>
+ operator<=>(const multimap<_K1, _T1, _C1, _A1>&,
+ const multimap<_K1, _T1, _C1, _A1>&);
+#else
template<typename _K1, typename _T1, typename _C1, typename _A1>
friend bool
operator<(const multimap<_K1, _T1, _C1, _A1>&,
const multimap<_K1, _T1, _C1, _A1>&);
+#endif
};
#if __cpp_deduction_guides >= 201606
multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> multimap<_Key, _Tp, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
/**
* @brief Multimap equality comparison.
const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
{ return __x._M_t == __y._M_t; }
+#if __cpp_lib_three_way_comparison
+ /**
+ * @brief Multimap ordering relation.
+ * @param __x A `multimap`.
+ * @param __y A `multimap` of the same type as `x`.
+ * @return A value indicating whether `__x` is less than, equal to,
+ * greater than, or incomparable with `__y`.
+ *
+ * This is a total ordering relation. It is linear in the size of the
+ * maps. The elements must be comparable with @c <.
+ *
+ * See `std::lexicographical_compare_three_way()` for how the determination
+ * is made. This operator is used to synthesize relational operators like
+ * `<` and `>=` etc.
+ */
+ template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<pair<const _Key, _Tp>>
+ operator<=>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
+ const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
+ { return __x._M_t <=> __y._M_t; }
+#else
/**
* @brief Multimap ordering relation.
* @param __x A %multimap.
operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
{ return !(__x < __y); }
+#endif // three-way comparison
/// See std::multimap::swap().
template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
operator==(const multiset<_K1, _C1, _A1>&,
const multiset<_K1, _C1, _A1>&);
+#if __cpp_lib_three_way_comparison
+ template<typename _K1, typename _C1, typename _A1>
+ friend __detail::__synth3way_t<_K1>
+ operator<=>(const multiset<_K1, _C1, _A1>&,
+ const multiset<_K1, _C1, _A1>&);
+#else
template<typename _K1, typename _C1, typename _A1>
friend bool
operator< (const multiset<_K1, _C1, _A1>&,
const multiset<_K1, _C1, _A1>&);
+#endif
};
#if __cpp_deduction_guides >= 201606
multiset(initializer_list<_Key>, _Allocator)
-> multiset<_Key, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
/**
* @brief Multiset equality comparison.
const multiset<_Key, _Compare, _Alloc>& __y)
{ return __x._M_t == __y._M_t; }
+#if __cpp_lib_three_way_comparison
+ /**
+ * @brief Multiset ordering relation.
+ * @param __x A `multiset`.
+ * @param __y A `multiset` of the same type as `x`.
+ * @return A value indicating whether `__x` is less than, equal to,
+ * greater than, or incomparable with `__y`.
+ *
+ * This is a total ordering relation. It is linear in the size of the
+ * maps. The elements must be comparable with @c <.
+ *
+ * See `std::lexicographical_compare_three_way()` for how the determination
+ * is made. This operator is used to synthesize relational operators like
+ * `<` and `>=` etc.
+ */
+ template<typename _Key, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<_Key>
+ operator<=>(const multiset<_Key, _Compare, _Alloc>& __x,
+ const multiset<_Key, _Compare, _Alloc>& __y)
+ { return __x._M_t <=> __y._M_t; }
+#else
/**
* @brief Multiset ordering relation.
* @param __x A %multiset.
operator>=(const multiset<_Key, _Compare, _Alloc>& __x,
const multiset<_Key, _Compare, _Alloc>& __y)
{ return !(__x < __y); }
+#endif // three-way comparison
/// See std::multiset::swap().
template<typename _Key, typename _Compare, typename _Alloc>
friend bool
operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
+#if __cpp_lib_three_way_comparison
+ template<typename _K1, typename _C1, typename _A1>
+ friend __detail::__synth3way_t<_K1>
+ operator<=>(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
+#else
template<typename _K1, typename _C1, typename _A1>
friend bool
operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
+#endif
};
#if __cpp_deduction_guides >= 201606
set(initializer_list<_Key>, _Allocator)
-> set<_Key, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
/**
* @brief Set equality comparison.
const set<_Key, _Compare, _Alloc>& __y)
{ return __x._M_t == __y._M_t; }
+#if __cpp_lib_three_way_comparison
+ /**
+ * @brief Set ordering relation.
+ * @param __x A `set`.
+ * @param __y A `set` of the same type as `x`.
+ * @return A value indicating whether `__x` is less than, equal to,
+ * greater than, or incomparable with `__y`.
+ *
+ * This is a total ordering relation. It is linear in the size of the
+ * maps. The elements must be comparable with @c <.
+ *
+ * See `std::lexicographical_compare_three_way()` for how the determination
+ * is made. This operator is used to synthesize relational operators like
+ * `<` and `>=` etc.
+ */
+ template<typename _Key, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<_Key>
+ operator<=>(const set<_Key, _Compare, _Alloc>& __x,
+ const set<_Key, _Compare, _Alloc>& __y)
+ { return __x._M_t <=> __y._M_t; }
+#else
/**
* @brief Set ordering relation.
* @param __x A %set.
operator>=(const set<_Key, _Compare, _Alloc>& __x,
const set<_Key, _Compare, _Alloc>& __y)
{ return !(__x < __y); }
+#endif // three-way comparison
/// See std::set::swap().
template<typename _Key, typename _Compare, typename _Alloc>
operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
{ return __x._M_node == __y._M_node; }
+#if ! __cpp_lib_three_way_comparison
friend bool
operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
{ return __x._M_node != __y._M_node; }
+#endif
_Base_ptr _M_node;
};
operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
{ return __x._M_node == __y._M_node; }
+#if ! __cpp_lib_three_way_comparison
friend bool
operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT
{ return __x._M_node != __y._M_node; }
+#endif
_Base_ptr _M_node;
};
&& std::equal(__x.begin(), __x.end(), __y.begin());
}
+#if __cpp_lib_three_way_comparison
+ friend auto
+ operator<=>(const _Rb_tree& __x, const _Rb_tree& __y)
+ {
+ if constexpr (requires { typename __detail::__synth3way_t<_Val>; })
+ return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
+ __y.begin(), __y.end(),
+ __detail::__synth3way);
+ }
+#else
friend bool
operator<(const _Rb_tree& __x, const _Rb_tree& __y)
{
friend bool _GLIBCXX_DEPRECATED
operator>=(const _Rb_tree& __x, const _Rb_tree& __y)
{ return !(__x < __y); }
+#endif
};
template<typename _Key, typename _Val, typename _KeyOfValue,
map(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> map<_Key, _Tp, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
template<typename _Key, typename _Tp,
typename _Compare, typename _Allocator>
const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() == __rhs._M_base(); }
+#if __cpp_lib_three_way_comparison
+ template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<pair<const _Key, _Tp>>
+ operator<=>(const map<_Key, _Tp, _Compare, _Alloc>& __lhs,
+ const map<_Key, _Tp, _Compare, _Alloc>& __rhs)
+ { return __lhs._M_base() <=> __rhs._M_base(); }
+#else
template<typename _Key, typename _Tp,
typename _Compare, typename _Allocator>
inline bool
operator>(const map<_Key, _Tp, _Compare, _Allocator>& __lhs,
const map<_Key, _Tp, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() > __rhs._M_base(); }
+#endif // three-way comparison
template<typename _Key, typename _Tp,
typename _Compare, typename _Allocator>
const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() == __rhs._M_base(); }
+#if __cpp_lib_three_way_comparison
+ template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<pair<const _Key, _Tp>>
+ operator<=>(const multimap<_Key, _Tp, _Compare, _Alloc>& __lhs,
+ const multimap<_Key, _Tp, _Compare, _Alloc>& __rhs)
+ { return __lhs._M_base() <=> __rhs._M_base(); }
+#else
template<typename _Key, typename _Tp,
typename _Compare, typename _Allocator>
inline bool
operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs,
const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() > __rhs._M_base(); }
+#endif // three-way comparison
template<typename _Key, typename _Tp,
typename _Compare, typename _Allocator>
multiset(initializer_list<_Key>, _Allocator)
-> multiset<_Key, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
template<typename _Key, typename _Compare, typename _Allocator>
inline bool
const multiset<_Key, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() == __rhs._M_base(); }
+#if __cpp_lib_three_way_comparison
+ template<typename _Key, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<_Key>
+ operator<=>(const multiset<_Key, _Compare, _Alloc>& __lhs,
+ const multiset<_Key, _Compare, _Alloc>& __rhs)
+ { return __lhs._M_base() <=> __rhs._M_base(); }
+#else
template<typename _Key, typename _Compare, typename _Allocator>
inline bool
operator!=(const multiset<_Key, _Compare, _Allocator>& __lhs,
operator>(const multiset<_Key, _Compare, _Allocator>& __lhs,
const multiset<_Key, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() > __rhs._M_base(); }
+#endif // three-way comparison
template<typename _Key, typename _Compare, typename _Allocator>
void
set(initializer_list<_Key>, _Allocator)
-> set<_Key, less<_Key>, _Allocator>;
-#endif
+#endif // deduction guides
template<typename _Key, typename _Compare, typename _Allocator>
inline bool
const set<_Key, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() == __rhs._M_base(); }
+#if __cpp_lib_three_way_comparison
+ template<typename _Key, typename _Compare, typename _Alloc>
+ inline __detail::__synth3way_t<_Key>
+ operator<=>(const set<_Key, _Compare, _Alloc>& __lhs,
+ const set<_Key, _Compare, _Alloc>& __rhs)
+ { return __lhs._M_base() <=> __rhs._M_base(); }
+#else
template<typename _Key, typename _Compare, typename _Allocator>
inline bool
operator!=(const set<_Key, _Compare, _Allocator>& __lhs,
operator>(const set<_Key, _Compare, _Allocator>& __lhs,
const set<_Key, _Compare, _Allocator>& __rhs)
{ return __lhs._M_base() > __rhs._M_base(); }
+#endif // three-way comparison
template<typename _Key, typename _Compare, typename _Allocator>
void
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <map>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::map<int, int> c1{ {1,1}, {2,1}, {3,1} };
+ std::map<int, int> c2{ {1,1}, {2,1}, {3,1}, {4,1} };
+ std::map<int, int> c3{ {1,1}, {2,1}, {3,2} };
+ VERIFY( c1 == c1 );
+ VERIFY( std::is_eq(c1 <=> c1) );
+ VERIFY( c1 < c2 );
+ VERIFY( std::is_lt(c1 <=> c2) );
+ VERIFY( c1 < c3 );
+ VERIFY( std::is_lt(c1 <=> c3) );
+ VERIFY( c2 < c3 );
+ VERIFY( std::is_lt(c2 <=> c3) );
+
+ static_assert( std::totally_ordered<std::map<int, int>> );
+
+ static_assert( std::three_way_comparable<std::map<int, int>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::map<int, float>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::map<int, float>,
+ std::weak_ordering> );
+ static_assert( std::three_way_comparable<std::map<int, float>,
+ std::partial_ordering> );
+
+ struct E
+ {
+ bool operator==(E) { return true; }
+ };
+ static_assert( ! std::totally_ordered<std::map<int, E>> );
+ static_assert( ! std::three_way_comparable<E> );
+ static_assert( ! std::three_way_comparable<std::map<int, E>> );
+}
+
+void
+test02()
+{
+ struct W
+ {
+ int value = 0;
+
+ bool operator==(W rhs) const noexcept
+ { return (value | 1) == (rhs.value | 1); }
+
+ std::weak_ordering
+ operator<=>(W rhs) const noexcept
+ { return (value | 1) <=> (rhs.value | 1); }
+ };
+
+ static_assert( std::totally_ordered<std::map<int, W>> );
+
+ using P = std::pair<const W, W>;
+ std::map<W, W> c1{ P{1,1}, P{2,2}, P{3,3} }, c2{ P{1,0}, P{3,2}, P{3,3} };
+ static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
+ VERIFY( c1 == c2 );
+ VERIFY( std::is_eq(c1 <=> c2) );
+}
+
+void
+test04()
+{
+ struct L
+ {
+ int value = 0;
+
+ bool operator<(L rhs) const noexcept { return value < rhs.value; }
+ };
+
+ static_assert( std::totally_ordered<std::map<int, L>> );
+
+ using P = std::pair<const L, L>;
+ std::map<L, L> c{ P{1,1}, P{2,2}, P{3,3} }, d{ P{1,1}, P{2,2}, P{3,4} };
+ static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
+ VERIFY( std::is_lt(c <=> d) );
+}
+
+// Associative container iterators are not random access
+static_assert( ! std::totally_ordered<std::map<int, int>::iterator> );
+static_assert( ! std::three_way_comparable<std::map<int, int>::iterator> );
+
+int
+main()
+{
+ test01();
+ test02();
+ test04();
+}
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <map>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::multimap<int, int> c1{ {1,1}, {2,1}, {3,1} };
+ std::multimap<int, int> c2{ {1,1}, {2,1}, {3,1}, {4,1} };
+ std::multimap<int, int> c3{ {1,1}, {2,1}, {3,2} };
+ VERIFY( c1 == c1 );
+ VERIFY( std::is_eq(c1 <=> c1) );
+ VERIFY( c1 < c2 );
+ VERIFY( std::is_lt(c1 <=> c2) );
+ VERIFY( c1 < c3 );
+ VERIFY( std::is_lt(c1 <=> c3) );
+ VERIFY( c2 < c3 );
+ VERIFY( std::is_lt(c2 <=> c3) );
+
+ static_assert( std::totally_ordered<std::multimap<int, int>> );
+
+ static_assert( std::three_way_comparable<std::multimap<int, int>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::multimap<int, float>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::multimap<int, float>,
+ std::weak_ordering> );
+ static_assert( std::three_way_comparable<std::multimap<int, float>,
+ std::partial_ordering> );
+
+ struct E
+ {
+ bool operator==(E) { return true; }
+ };
+ static_assert( ! std::totally_ordered<std::multimap<int, E>> );
+ static_assert( ! std::three_way_comparable<E> );
+ static_assert( ! std::three_way_comparable<std::multimap<int, E>> );
+}
+
+void
+test02()
+{
+ struct W
+ {
+ int value = 0;
+
+ bool operator==(W rhs) const noexcept
+ { return (value | 1) == (rhs.value | 1); }
+
+ std::weak_ordering
+ operator<=>(W rhs) const noexcept
+ { return (value | 1) <=> (rhs.value | 1); }
+ };
+
+ static_assert( std::totally_ordered<std::multimap<int, W>> );
+
+ using P = std::pair<const W, W>;
+ std::multimap<W, W> c1{ P{1,1}, P{2,2}, P{3,3} }, c2{ P{1,0}, P{3,2}, P{3,3} };
+ static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
+ VERIFY( c1 == c2 );
+ VERIFY( std::is_eq(c1 <=> c2) );
+}
+
+void
+test04()
+{
+ struct L
+ {
+ int value = 0;
+
+ bool operator<(L rhs) const noexcept { return value < rhs.value; }
+ };
+
+ static_assert( std::totally_ordered<std::multimap<int, L>> );
+
+ using P = std::pair<const L, L>;
+ std::multimap<L, L> c{ P{1,1}, P{2,2}, P{3,3} }, d{ P{1,1}, P{2,2}, P{3,4} };
+ static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
+ VERIFY( std::is_lt(c <=> d) );
+}
+
+// Associative container iterators are not random access
+static_assert( ! std::totally_ordered<std::multimap<int, int>::iterator> );
+static_assert( ! std::three_way_comparable<std::multimap<int, int>::iterator> );
+
+int
+main()
+{
+ test01();
+ test02();
+ test04();
+}
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <set>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::multiset<int> c1{ 1, 2, 3 }, c2{ 1, 2, 3, 4 }, c3{ 1, 2, 4 };
+ VERIFY( c1 == c1 );
+ VERIFY( std::is_eq(c1 <=> c1) );
+ VERIFY( c1 < c2 );
+ VERIFY( std::is_lt(c1 <=> c2) );
+ VERIFY( c1 < c3 );
+ VERIFY( std::is_lt(c1 <=> c3) );
+ VERIFY( c2 < c3 );
+ VERIFY( std::is_lt(c2 <=> c3) );
+
+ static_assert( std::totally_ordered<std::multiset<int>> );
+
+ static_assert( std::three_way_comparable<std::multiset<int>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::multiset<float>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::multiset<float>,
+ std::weak_ordering> );
+ static_assert( std::three_way_comparable<std::multiset<float>,
+ std::partial_ordering> );
+
+ struct E
+ {
+ bool operator==(E) { return true; }
+ };
+ static_assert( ! std::totally_ordered<std::multiset<E>> );
+ static_assert( ! std::three_way_comparable<E> );
+ static_assert( ! std::three_way_comparable<std::multiset<E>> );
+}
+
+void
+test02()
+{
+ struct W
+ {
+ int value = 0;
+
+ bool operator==(W rhs) const noexcept
+ { return (value | 1) == (rhs.value | 1); }
+
+ std::weak_ordering
+ operator<=>(W rhs) const noexcept
+ { return (value | 1) <=> (rhs.value | 1); }
+ };
+
+ static_assert( std::totally_ordered<std::multiset<W>> );
+
+ std::multiset<W> c1{ {1}, {2}, {3} }, c2{ {0}, {3}, {3} };
+ static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
+ VERIFY( c1 == c2 );
+ VERIFY( std::is_eq(c1 <=> c2) );
+}
+
+void
+test04()
+{
+ struct L
+ {
+ int value = 0;
+
+ bool operator<(L rhs) const noexcept { return value < rhs.value; }
+ };
+
+ static_assert( std::totally_ordered<std::multiset<L>> );
+
+ std::multiset<L> c{ {1}, {2}, {3} }, d{ {1}, {2}, {3}, {4} };
+ static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
+ VERIFY( std::is_lt(c <=> d) );
+}
+
+// Associative container iterators are not random access
+static_assert( ! std::totally_ordered<std::multiset<int>::iterator> );
+static_assert( ! std::three_way_comparable<std::multiset<int>::iterator> );
+
+int
+main()
+{
+ test01();
+ test02();
+ test04();
+}
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do run { target c++2a } }
+
+#include <set>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::set<int> c1{ 1, 2, 3 }, c2{ 1, 2, 3, 4 }, c3{ 1, 2, 4 };
+ VERIFY( c1 == c1 );
+ VERIFY( std::is_eq(c1 <=> c1) );
+ VERIFY( c1 < c2 );
+ VERIFY( std::is_lt(c1 <=> c2) );
+ VERIFY( c1 < c3 );
+ VERIFY( std::is_lt(c1 <=> c3) );
+ VERIFY( c2 < c3 );
+ VERIFY( std::is_lt(c2 <=> c3) );
+
+ static_assert( std::totally_ordered<std::set<int>> );
+
+ static_assert( std::three_way_comparable<std::set<int>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::set<float>,
+ std::strong_ordering> );
+ static_assert( ! std::three_way_comparable<std::set<float>,
+ std::weak_ordering> );
+ static_assert( std::three_way_comparable<std::set<float>,
+ std::partial_ordering> );
+
+ struct E
+ {
+ bool operator==(E) { return true; }
+ };
+ static_assert( ! std::totally_ordered<std::set<E>> );
+ static_assert( ! std::three_way_comparable<E> );
+ static_assert( ! std::three_way_comparable<std::set<E>> );
+}
+
+void
+test02()
+{
+ struct W
+ {
+ int value = 0;
+
+ bool operator==(W rhs) const noexcept
+ { return (value | 1) == (rhs.value | 1); }
+
+ std::weak_ordering
+ operator<=>(W rhs) const noexcept
+ { return (value | 1) <=> (rhs.value | 1); }
+ };
+
+ static_assert( std::totally_ordered<std::set<W>> );
+
+ std::set<W> c1{ {1}, {2}, {3} }, c2{ {0}, {3}, {3} };
+ static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
+ VERIFY( c1 == c2 );
+ VERIFY( std::is_eq(c1 <=> c2) );
+}
+
+void
+test04()
+{
+ struct L
+ {
+ int value = 0;
+
+ bool operator<(L rhs) const noexcept { return value < rhs.value; }
+ };
+
+ static_assert( std::totally_ordered<std::set<L>> );
+
+ std::set<L> c{ {1}, {2}, {3} }, d{ {1}, {2}, {3}, {4} };
+ static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
+ VERIFY( std::is_lt(c <=> d) );
+}
+
+// Associative container iterators are not random access
+static_assert( ! std::totally_ordered<std::set<int>::iterator> );
+static_assert( ! std::three_way_comparable<std::set<int>::iterator> );
+
+int
+main()
+{
+ test01();
+ test02();
+ test04();
+}