This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Asymmetry of user-difined swap and distance
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Maxim Dementiev <max at e-soft dot ru>
- Cc: libstdc++ at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Fri, 7 Aug 2009 19:19:03 +0100
- Subject: Re: Asymmetry of user-difined swap and distance
- References: <web-217729467@office.m-10.ru>
2009/8/7 Maxim Dementiev:
>
> It means that swap for user types could be defined either in std namespace
> or in the user type namespace (argument-dependent name lookup).
Yes, this is intentional. swap() is a point of customisation point,
see http://www.ddj.com/cpp/184401876 and the definition in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1691.html
> On the other hand, distance (advance, etc.) for user types must be defined
> in std namespace.
There is no need to customise std::distance(), or certainly a lot less
need, because the Standard Library can provide optimal implementations
for all possible iterator categories. The generic swap() function in
namespace std won't even work with some types and is sub-optimal for
others.
Jonathan