|
Boost : |
From: Ullrich Koethe (u.koethe_at_[hidden])
Date: 2001-07-11 15:18:50
David Abrahams wrote:
>
> Doesn't work, I think:
>
> template <class Container, class Iterator>
> void test_stability(Container& c, Iterator x)
> {
> Iterator y = x;
> ++y;
> std::iterator_traits<Iterator>::pointer p = &*y;
> std::iterator_traits<Iterator>::value_type v = *y;
> c.erase(x);
> assert(p == &*y); // test pointer and iterator stability
> }
>
Too bad. But it could be repaired if the vector actually stored
"pair<key,value>*". The additional indirection could be hidden in the
access functions. Of course, performance will suffer.
On the other hand,
assert(v.first == (*y).first);
assert(v.second == (*y).second);
would work, and I regard this as the more important requirement. If the
mapped object were stored by pointer, even
assert(&v.second == &(*y).second);
would work. I regard the pair stored in a map as as helper object whose
identity is of no interest.
Ulli
-- ________________________________________________________________ | | | Ullrich Koethe Universität Hamburg / University of Hamburg | | FB Informatik / Dept. of Computer Science | | AB Kognitive Systeme / Cognitive Systems Group | | | | Phone: +49 (0)40 42883-2573 Vogt-Koelln-Str. 30 | | Fax: +49 (0)40 42883-2572 D - 22527 Hamburg | | Email: u.koethe_at_[hidden] Germany | | koethe_at_[hidden] | | WWW: http://kogs-www.informatik.uni-hamburg.de/~koethe/ | |________________________________________________________________|
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk