[cfe-dev] Specializing std::swap
James Dennett
james.dennett at gmail.com
Wed May 22 19:47:06 PDT 2013
On Wed, May 22, 2013 at 7:14 PM, Aleksandar Fabijanic <aleskx at gmail.com>wrote:
> Hi,
>
> It was stated in this bug report
>
> http://llvm.org/bugs/show_bug.cgi?id=10248
>
> that specializing swap for non-std types in std namespace, although
> legal, is considered fragile. It is not entirely clear from the
> response why is that so.
>
> Can someone shed some light on this?
>
I'm not sure this is topical for cfe-dev, as it's just a question about C++.
C++ doesn't have partial specialization for templates, so it's not possible
to define a std::swap for a user-define template. You could write an
overload, except that it's not permitted to add overloads to namespace std.
On the bright side, ADL means that it's not necessary to put those in
namespace std anyway, so long as people use swap properly (such that ADL is
enabled).
-- James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130522/45eb7233/attachment.html>
More information about the cfe-dev
mailing list