This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH][libstdc++-v3 parallel mode] Enable user-defined swap
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: François Dumont <francois dot cppdevs at free dot fr>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Mon, 7 Mar 2011 20:25:08 +0000
- Subject: Re: [PATCH][libstdc++-v3 parallel mode] Enable user-defined swap
- References: <4D3DB1E0.5010008@kit.edu> <20110124101204.22a18cb4@shotwell> <4D67B800.2090403@kit.edu> <4D753B8A.9020200@free.fr>
On 7 March 2011 20:09, François Dumont wrote:
> Hi
>
> ? ?Sorry if this is trivial but I don't really understand the rational of
> such modifications.
>
> ? ?It is supposed to have libstdc++ use user defined overloads of swap when
> available. But if so shouldn't it be overloaded in the std namespace ? I
No, users cannot add overloads to namespace std.
'swap' is a customization point, intended to allow users to provide
their own versions, found by argument-dependent lookup. The C++0x
standard makes this more explicit, see [swappable.requirements] in
Clause 17, which says the set of swap functions considered for a
Swappable type includes those found by argument-dependent lookup. The
way to do that is using the standard idiom of "using std::swap"
followed by an unqualified call.
> remember having read something like that but I am not sure it was in the C++
> Standard or it was about the swap algo.
>
> ? ?If we open libstdc++ to use swap defined in any namespace shouln't we do
> the same for all other algos used internally. For instance this patch use
> std::iter_swap, shouldn't it use:
>
> using std::iter_swap;
> iter_swap(...);
No, because the standard says that all effects in terms of function
calls are assumed to call the version in std:: unless otherwise
specified. swap is specified otherwise.