Commit 596676d6 by Jonathan Wakely

libstdc++: Add comparison operators to types from Utilities clause

Some more C++20 changes from P1614R2, "The Mothership has Landed".

This removes all redundant equality and inequality operators in the
Utilities clause, as they can be synthesized from the remaining equality
operators.

It also removes the single redundant operator in the Localization
clause, because it didn't seem worth doing in a separate commit.

	* include/bits/allocator.h (operator!=): Do not define for C++20.
	* include/bits/locale_classes.h (operator!=): Likewise.
	* include/bits/std_function.h (operator==(nullptr_t, const function&))
	(operator!=(const function&, nullptr_t))
	(operator!=(nullptr_t, const function&)): Likewise.
	* include/ext/bitmap_allocator.h (operator!=): Likewise.
	* include/ext/debug_allocator.h (operator!=): Likewise.
	* include/ext/extptr_allocator.h (operator!=): Likewise.
	* include/ext/malloc_allocator.h (operator!=): Likewise.
	* include/ext/mt_allocator.h (operator!=): Likewise.
	* include/ext/new_allocator.h (operator!=): Likewise.
	* include/ext/pool_allocator.h (operator!=): Likewise.
	* include/ext/throw_allocator.h (operator!=): Likewise.
	* include/std/bitset (bitset::operator!=): Likewise.
	* include/std/memory_resource (operator!=): Likewise.
	* include/std/scoped_allocator (operator!=): Likewise.
parent 4714fd14
2020-04-15 Jonathan Wakely <jwakely@redhat.com> 2020-04-15 Jonathan Wakely <jwakely@redhat.com>
* include/bits/allocator.h (operator!=): Do not define for C++20.
* include/bits/locale_classes.h (operator!=): Likewise.
* include/bits/std_function.h (operator==(nullptr_t, const function&))
(operator!=(const function&, nullptr_t))
(operator!=(nullptr_t, const function&)): Likewise.
* include/ext/bitmap_allocator.h (operator!=): Likewise.
* include/ext/debug_allocator.h (operator!=): Likewise.
* include/ext/extptr_allocator.h (operator!=): Likewise.
* include/ext/malloc_allocator.h (operator!=): Likewise.
* include/ext/mt_allocator.h (operator!=): Likewise.
* include/ext/new_allocator.h (operator!=): Likewise.
* include/ext/pool_allocator.h (operator!=): Likewise.
* include/ext/throw_allocator.h (operator!=): Likewise.
* include/std/bitset (bitset::operator!=): Likewise.
* include/std/memory_resource (operator!=): Likewise.
* include/std/scoped_allocator (operator!=): Likewise.
* include/std/typeindex (operator<=>): Define for C++20. * include/std/typeindex (operator<=>): Define for C++20.
* testsuite/20_util/typeindex/comparison_operators_c++20.cc: New test. * testsuite/20_util/typeindex/comparison_operators_c++20.cc: New test.
......
...@@ -196,9 +196,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -196,9 +196,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
friend _GLIBCXX20_CONSTEXPR bool friend _GLIBCXX20_CONSTEXPR bool
operator!=(const allocator&, const allocator&) _GLIBCXX_NOTHROW operator!=(const allocator&, const allocator&) _GLIBCXX_NOTHROW
{ return false; } { return false; }
#endif
// Inherit everything else. // Inherit everything else.
}; };
...@@ -209,11 +211,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -209,11 +211,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NOTHROW _GLIBCXX_NOTHROW
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _T1, typename _T2> template<typename _T1, typename _T2>
inline _GLIBCXX20_CONSTEXPR bool inline _GLIBCXX20_CONSTEXPR bool
operator!=(const allocator<_T1>&, const allocator<_T2>&) operator!=(const allocator<_T1>&, const allocator<_T2>&)
_GLIBCXX_NOTHROW _GLIBCXX_NOTHROW
{ return false; } { return false; }
#endif
// Invalid allocator<cv T> partial specializations. // Invalid allocator<cv T> partial specializations.
// allocator_traits::rebind_alloc can be used to form a valid allocator type. // allocator_traits::rebind_alloc can be used to form a valid allocator type.
......
...@@ -254,6 +254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -254,6 +254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool bool
operator==(const locale& __other) const throw(); operator==(const locale& __other) const throw();
#if __cpp_impl_three_way_comparison < 201907L
/** /**
* @brief Locale inequality. * @brief Locale inequality.
* *
...@@ -263,6 +264,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -263,6 +264,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool bool
operator!=(const locale& __other) const throw() operator!=(const locale& __other) const throw()
{ return !(this->operator==(__other)); } { return !(this->operator==(__other)); }
#endif
/** /**
* @brief Compare two strings according to collate. * @brief Compare two strings according to collate.
......
...@@ -680,6 +680,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -680,6 +680,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
{ return !static_cast<bool>(__f); } { return !static_cast<bool>(__f); }
#if __cpp_impl_three_way_comparison < 201907L
/// @overload /// @overload
template<typename _Res, typename... _Args> template<typename _Res, typename... _Args>
inline bool inline bool
...@@ -703,7 +704,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -703,7 +704,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline bool inline bool
operator!=(nullptr_t, const function<_Res(_Args...)>& __f) noexcept operator!=(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
{ return static_cast<bool>(__f); } { return static_cast<bool>(__f); }
#endif
// [20.7.15.2.7] specialized algorithms // [20.7.15.2.7] specialized algorithms
......
...@@ -1098,11 +1098,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1098,11 +1098,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const bitmap_allocator<_Tp2>&) throw() const bitmap_allocator<_Tp2>&) throw()
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
bool bool
operator!=(const bitmap_allocator<_Tp1>&, operator!=(const bitmap_allocator<_Tp1>&,
const bitmap_allocator<_Tp2>&) throw() const bitmap_allocator<_Tp2>&) throw()
{ return false; } { return false; }
#endif
// Static member definitions. // Static member definitions.
template<typename _Tp> template<typename _Tp>
......
...@@ -179,11 +179,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -179,11 +179,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const debug_allocator<_Alloc2>& __rhs) _GLIBCXX_NOTHROW const debug_allocator<_Alloc2>& __rhs) _GLIBCXX_NOTHROW
{ return __lhs._M_allocator == debug_allocator(__rhs)._M_allocator; } { return __lhs._M_allocator == debug_allocator(__rhs)._M_allocator; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Alloc2> template<typename _Alloc2>
friend bool friend bool
operator!=(const debug_allocator& __lhs, operator!=(const debug_allocator& __lhs,
const debug_allocator<_Alloc2>& __rhs) _GLIBCXX_NOTHROW const debug_allocator<_Alloc2>& __rhs) _GLIBCXX_NOTHROW
{ return !(__lhs == __rhs); } { return !(__lhs == __rhs); }
#endif
}; };
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
......
...@@ -138,6 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -138,6 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator==(const _ExtPtr_allocator& __rarg) const operator==(const _ExtPtr_allocator& __rarg) const
{ return _M_real_alloc == __rarg._M_real_alloc; } { return _M_real_alloc == __rarg._M_real_alloc; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Up> template<typename _Up>
inline bool inline bool
operator!=(const _ExtPtr_allocator<_Up>& __rarg) const operator!=(const _ExtPtr_allocator<_Up>& __rarg) const
...@@ -146,6 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -146,6 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline bool inline bool
operator!=(const _ExtPtr_allocator& __rarg) const operator!=(const _ExtPtr_allocator& __rarg) const
{ return _M_real_alloc != __rarg._M_real_alloc; } { return _M_real_alloc != __rarg._M_real_alloc; }
#endif
template<typename _Up> template<typename _Up>
inline friend void inline friend void
......
...@@ -174,11 +174,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -174,11 +174,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NOTHROW _GLIBCXX_NOTHROW
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Up> template<typename _Up>
friend _GLIBCXX20_CONSTEXPR bool friend _GLIBCXX20_CONSTEXPR bool
operator!=(const malloc_allocator&, const malloc_allocator<_Up>&) operator!=(const malloc_allocator&, const malloc_allocator<_Up>&)
_GLIBCXX_NOTHROW _GLIBCXX_NOTHROW
{ return false; } { return false; }
#endif
private: private:
_GLIBCXX_CONSTEXPR size_type _GLIBCXX_CONSTEXPR size_type
......
...@@ -771,10 +771,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -771,10 +771,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator==(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&) operator==(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&)
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Tp, typename _Poolp> template<typename _Tp, typename _Poolp>
inline bool inline bool
operator!=(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&) operator!=(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&)
{ return false; } { return false; }
#endif
#undef __thread_default #undef __thread_default
......
...@@ -173,11 +173,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -173,11 +173,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NOTHROW _GLIBCXX_NOTHROW
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Up> template<typename _Up>
friend _GLIBCXX20_CONSTEXPR bool friend _GLIBCXX20_CONSTEXPR bool
operator!=(const new_allocator&, const new_allocator<_Up>&) operator!=(const new_allocator&, const new_allocator<_Up>&)
_GLIBCXX_NOTHROW _GLIBCXX_NOTHROW
{ return false; } { return false; }
#endif
private: private:
_GLIBCXX_CONSTEXPR size_type _GLIBCXX_CONSTEXPR size_type
......
...@@ -198,10 +198,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -198,10 +198,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator==(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&) operator==(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&)
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Tp> template<typename _Tp>
inline bool inline bool
operator!=(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&) operator!=(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&)
{ return false; } { return false; }
#endif
template<typename _Tp> template<typename _Tp>
_Atomic_word _Atomic_word
......
...@@ -895,11 +895,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -895,11 +895,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const throw_allocator_base<_Tp, _Cond>&) const throw_allocator_base<_Tp, _Cond>&)
{ return true; } { return true; }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Tp, typename _Cond> template<typename _Tp, typename _Cond>
inline bool inline bool
operator!=(const throw_allocator_base<_Tp, _Cond>&, operator!=(const throw_allocator_base<_Tp, _Cond>&,
const throw_allocator_base<_Tp, _Cond>&) const throw_allocator_base<_Tp, _Cond>&)
{ return false; } { return false; }
#endif
/// Allocator throwing via limit condition. /// Allocator throwing via limit condition.
template<typename _Tp> template<typename _Tp>
......
...@@ -1306,9 +1306,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -1306,9 +1306,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
{ return this->_M_is_equal(__rhs); } { return this->_M_is_equal(__rhs); }
#if __cpp_impl_three_way_comparison < 201907L
bool bool
operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
{ return !this->_M_is_equal(__rhs); } { return !this->_M_is_equal(__rhs); }
#endif
//@} //@}
/** /**
......
...@@ -122,10 +122,11 @@ namespace pmr ...@@ -122,10 +122,11 @@ namespace pmr
operator==(const memory_resource& __a, const memory_resource& __b) noexcept operator==(const memory_resource& __a, const memory_resource& __b) noexcept
{ return &__a == &__b || __a.is_equal(__b); } { return &__a == &__b || __a.is_equal(__b); }
#if __cpp_impl_three_way_comparison < 201907L
inline bool inline bool
operator!=(const memory_resource& __a, const memory_resource& __b) noexcept operator!=(const memory_resource& __a, const memory_resource& __b) noexcept
{ return !(__a == __b); } { return !(__a == __b); }
#endif
// C++17 23.12.3 Class template polymorphic_allocator // C++17 23.12.3 Class template polymorphic_allocator
template<typename _Tp> template<typename _Tp>
...@@ -362,12 +363,13 @@ namespace pmr ...@@ -362,12 +363,13 @@ namespace pmr
const polymorphic_allocator<_Tp2>& __b) noexcept const polymorphic_allocator<_Tp2>& __b) noexcept
{ return *__a.resource() == *__b.resource(); } { return *__a.resource() == *__b.resource(); }
#if __cpp_impl_three_way_comparison < 201907L
template<typename _Tp1, typename _Tp2> template<typename _Tp1, typename _Tp2>
inline bool inline bool
operator!=(const polymorphic_allocator<_Tp1>& __a, operator!=(const polymorphic_allocator<_Tp1>& __a,
const polymorphic_allocator<_Tp2>& __b) noexcept const polymorphic_allocator<_Tp2>& __b) noexcept
{ return !(__a == __b); } { return !(__a == __b); }
#endif
/// Parameters for tuning a pool resource's behaviour. /// Parameters for tuning a pool resource's behaviour.
struct pool_options struct pool_options
......
...@@ -500,12 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -500,12 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __a._M_inner == __b._M_inner; && __a._M_inner == __b._M_inner;
} }
#if __cpp_impl_three_way_comparison < 201907L
/// @related std::scoped_allocator_adaptor /// @related std::scoped_allocator_adaptor
template <typename _OutA1, typename _OutA2, typename... _InA> template <typename _OutA1, typename _OutA2, typename... _InA>
inline bool inline bool
operator!=(const scoped_allocator_adaptor<_OutA1, _InA...>& __a, operator!=(const scoped_allocator_adaptor<_OutA1, _InA...>& __a,
const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept
{ return !(__a == __b); } { return !(__a == __b); }
#endif
/// @} /// @}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment