This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Asymmetry of user-difined swap and distance
- From: "Maxim Dementiev" <max at e-soft dot ru>
- To: libstdc++ at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Fri, 07 Aug 2009 18:16:24 +0400
- Subject: Asymmetry of user-difined swap and distance
Hi,
Let's have a look at std::pair<>::swap and std::lower_bound<> implementations.
1. pair::swap in http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/bits/stl_pair.h?view=markup
void
swap(pair& __p)
{
using std::swap;
swap(first, __p.first);
swap(second, __p.second);
}
2. lower_bound in http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/bits/stl_algo.h?view=markup
_DistanceType __len = std::distance(__first, __last);
Now we need to use user-defined versions of swap and distance for corresponding types when we work with STL.
It means that swap for user types could be defined either in std namespace or in the user type namespace (argument-dependent name
lookup).
On the other hand, distance (advance, etc.) for user types must be defined in std namespace.
How come? Why this asymmetry?
Should we always extend std namespace?
Regards,
Maxim P. Dementiev