Skip to content

Commit

Permalink
libstdc++/pair: Define _S_const_assignable helper for C++20
Browse files Browse the repository at this point in the history
This is consistent with std::tuple's __const_assignable member function,
and will be reused when implementing the new pair::operator= overloads
from P2165R4.

libstdc++-v3/ChangeLog:

	* include/bits/stl_pair.h (pair::_S_const_assignable): Define,
	factored out from ...
	(pair::operator=): ... the constraints of the const overloads.
  • Loading branch information
Patrick Palka authored and ouuleilei-bot committed Jan 24, 2024
1 parent c2d62cd commit 61588ae
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions libstdc++-v3/include/bits/stl_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return false;
}

template<typename _U1, typename _U2>
static constexpr bool
_S_const_assignable()
{
if constexpr (is_assignable_v<const _T1&, _U1>)
return is_assignable_v<const _T2&, _U2>;
return false;
}

template<typename _U1, typename _U2>
static constexpr bool
_S_nothrow_assignable()
Expand Down Expand Up @@ -461,8 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Copy assignment operator (const)
constexpr const pair&
operator=(const pair& __p) const
requires is_copy_assignable_v<const first_type>
&& is_copy_assignable_v<const second_type>
requires (_S_const_assignable<const first_type&, const second_type&>())
{
first = __p.first;
second = __p.second;
Expand All @@ -472,8 +480,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Move assignment operator (const)
constexpr const pair&
operator=(pair&& __p) const
requires is_assignable_v<const first_type&, first_type>
&& is_assignable_v<const second_type&, second_type>
requires (_S_const_assignable<first_type, second_type>())
{
first = std::forward<first_type>(__p.first);
second = std::forward<second_type>(__p.second);
Expand All @@ -484,8 +491,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _U1, typename _U2>
constexpr const pair&
operator=(const pair<_U1, _U2>& __p) const
requires is_assignable_v<const first_type&, const _U1&>
&& is_assignable_v<const second_type&, const _U2&>
requires (_S_const_assignable<const _U1&, const _U2&>())
{
first = __p.first;
second = __p.second;
Expand All @@ -496,8 +502,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _U1, typename _U2>
constexpr const pair&
operator=(pair<_U1, _U2>&& __p) const
requires is_assignable_v<const first_type&, _U1>
&& is_assignable_v<const second_type&, _U2>
requires (_S_const_assignable<_U1, _U2>())
{
first = std::forward<_U1>(__p.first);
second = std::forward<_U2>(__p.second);
Expand Down

0 comments on commit 61588ae

Please sign in to comment.