[PATCH][libstdc++-v3 parallel mode] Enable user-defined swap
Jonathan Wakely
jwakely.gcc@gmail.com
Mon Mar 7 20:26:00 GMT 2011
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.
More information about the Libstdc++
mailing list