Topic: std::swap calling member-swap? (was: Re:


Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Thu, 2 Feb 2017 11:27:11 -0500
Raw View
--Apple-Mail=_19299DC4-33A3-4E8D-865D-DADCDBCE17D4
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

On Feb 2, 2017, at 5:27 AM, Marc Mutz <marc.mutz@kdab.com> wrote:
>=20
> Hi,
>=20
> I don't know the state of the default-swap proposal, but this here seems
> orthogonal, anyway:
>=20
> The following is intentionally kept very vague:
>=20
> I was wondering whether std::swap could not prefer to call a member-swap =
where
> it exists, and only otherwise perform the default 3-move-assignment that =
it
> has since C++11.
>=20
> A nice benefit of this would be that all the std::swap
> specialisations/overloads for (most) containers would go away, because th=
ey
> provide member-swap functions already.
>=20
> This would also mitigate the source-incompatibility described in this thr=
ead,
> as users could add member-swaps to their non-movable/non-copyable classes=
..

I=E2=80=99ve seen code in the wild where member swap calls std::swap using =
*this as one of the arguments.  So if we do this, we will silently turn a n=
on-zero amount of code into infinite recursion.

Howard

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/F054F2B0-AF77-42C7-A87E-6C8302CCDDEF%40gmail.com=
..

--Apple-Mail=_19299DC4-33A3-4E8D-865D-DADCDBCE17D4
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename=signature.asc
Content-Type: application/pgp-signature;
 name=signature.asc
Content-Description: Message signed with OpenPGP

-----BEGIN PGP SIGNATURE-----

iQIcBAEBCAAGBQJYk13fAAoJEGbcHCxKqhWCaf8P/1lfNVvjkn7DVlFcnzxq7gtO
II3t/H3KsNePd7lq/buZKGGNq4DsOmTFIwOEfc7YWDWnlELRlzrNj/COCUAWTsCE
twYBdDjahc2K0y7MrUb8XpOCe8qLlNstEyrLvXnpuKoZrUo1qGStTrtwhm23NiCj
LQeEonJIzhk74nJt2pZHqXLUVzdScVnbcq3fw9S9Wh/gNCw/BZ8LuuF/kxIyUlrv
wpg/coIv5GVJGaKdAiPbrvVgTBGgJ7uPJTPLOBnkULwDH5IKX9Jlyz6qAlZpkTf6
3dXUEJV1cCA3ZUko9gydDiXTBwpxExt6p5yo3Ee3Chvj04pbhhQHUyiWCMDT1BOD
f+vxyzzn/PiDPJCz8Hb3hiFi1MJzN0z0Sdppyjljh8ydGFgou71IjllUS8Ql1oFT
phnlQxLH9mcsJpVaYcQXWp8/hpJCJd8p7D7hpbm/UtwBJCfXRbqz9d7jG637olrd
Ce9T+OlK9tBQcZAaGinMuBkXpkK37kGzBNiG4aM6615U4O8CZK2Xpk1BQoUI8uKX
/lRfAs2kY0uZVn3IaydodTey4g5yychMq11Dfxp2dZ0jHi/z2KR9UUYDfyLbGsuZ
zy5CT2PcEAG7OZUy7moOtKssxGMAv5NPl9Eipm2do4SmwOWbblekc6LLyCZgaSEy
Z4hL93zb6VwqVAtV8Dqe
=VSAQ
-----END PGP SIGNATURE-----

--Apple-Mail=_19299DC4-33A3-4E8D-865D-DADCDBCE17D4--

.