From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH 1/2] libstdc++/pair: Define _S_const_assignable helper for C++20
Date: Tue, 23 Jan 2024 18:53:02 -0500 [thread overview]
Message-ID: <20240123235303.1540890-1-ppalka@redhat.com> (raw)
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.
---
libstdc++-v3/include/bits/stl_pair.h | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index acd0c7b58f9..b81b479ad43 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -404,6 +404,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()
@@ -468,8 +477,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;
@@ -479,8 +487,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);
@@ -491,8 +498,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;
@@ -503,8 +509,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);
--
2.43.0.386.ge02ecfcc53
next reply other threads:[~2024-01-23 23:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-23 23:53 Patrick Palka [this message]
2024-01-23 23:53 ` [PATCH 2/2] libstdc++: Implement P2165R4 changes to std::pair/tuple/etc Patrick Palka
2024-01-24 12:01 ` Jonathan Wakely
2024-01-24 12:08 ` Jonathan Wakely
2024-01-24 15:24 ` Patrick Palka
2024-01-24 17:27 ` Jonathan Wakely
2024-01-24 18:57 ` Patrick Palka
2024-01-24 19:47 ` Patrick Palka
2024-01-31 19:39 ` Patrick Palka
2024-01-31 19:41 ` Patrick Palka
2024-01-31 21:55 ` Jonathan Wakely
2024-01-24 21:16 ` Jonathan Wakely
2024-01-24 0:21 ` [PATCH 1/2] libstdc++/pair: Define _S_const_assignable helper for C++20 Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240123235303.1540890-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).