iter_swapping vector<bool>::iterator..
Chris Jefferson
caj@cs.york.ac.uk
Fri Mar 18 15:23:00 GMT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Paolo Carlini wrote:
| Chris Jefferson wrote:
|
|> I've just wandered across a problem in iter_swap.. that if you
|> specialise iter_swap to use swap, then you can't iter_swap
|> vector<bool>::iterators any more ¬_¬
|
|
| Why? Please explain, this is a serious issue, not a joke: we are talking
| about a 4.0 *regression*. For 4.0 we should definitely revert to the old
| behavior, in my opinion. Then we can try to figure out a better solution,
| but only for mainline. Also, please provide a testcase.
Sorry, I'll provide a bit more detail this time!
The problem is that vector<bool>::iterator returns a temporary
_Bit_Reference rather than a "proper" reference. If iter_swap is defined as:
void iter_swap(A a,B b) { swap(*a,*b); }
then as swap is defined as "void swap(T& t,U &u);", then you get the error:
invalid initialization of non-const reference of type
'std::_Bit_reference' from a temporary of type 'std::_Bit_reference'
According to my reading of the standard, the new behaviour is correct as
according to Table 47, a forward iterator must for "*a" return "T&", and
iter_swap only claims to work on forward iterators. Vector<bool> isn't a
proper container and it's iterators don't satisfy the conditions for
forward iterators. Also using swap is currently at "WP" position in the
defects list (number 187), as has been mentioned before.
While we are in our rights to break iter_swap for
vector<bool>::iterators, and it does produce a large speed improvement,
I agree that it's probably too close to 4.0 to start applying changes
and trying to fix things up now (and possibly breaking things or
changing behaviour seems like it would be more approriate to do in so_7)
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)
iD8DBQFCOvH73FpDzErifpIRAphlAJ9Sc2HqvzizsT3t2Z75ULq3PapDowCfZeE0
9ejFV7ownEGDke7P/1Hb4iQ=
=pnBJ
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: iter_swap.cc
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050318/d79700da/attachment.cc>
More information about the Libstdc++
mailing list