Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-07-11 14:57:41


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
}

-Dave

----- Original Message -----
From: "Ullrich Koethe" <u.koethe_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, July 11, 2001 3:36 PM
Subject: Re: [boost] challenge: stable_vector

> Jeremy Siek wrote:
> >
> > Yes, iterator stability would be problematic.
> >
>
> I think, a stable iterator for a sorted vecor could be achieved by means
> of an 'is_dirty()' function, sililar to a cache. ("stable" in the sense
> that it always points to the same element. Stable
> successors/predecessors cannot be guaranteed.):
>
> /* untested code */
> template <class SortedVector>
> class sorted_vector_iterator
> {
> SortedVector & its_vector;
> typename SortedVector::key_type its_key;
> typename SortedVector::value_type * its_element;
> typedef typename SortedVector::value_type value_type;
>
> void update()
> {
> if(its_vector.is_dirty())
> {
> its_element = &its_vector[its_key]; // or similar
> }
> }
>
> sorted_vector_iterator & operator++()
> {
> update();
> its_element++; // or similar
> return *this;
> }
>
> value_type operator*()
> {
> update();
> return *its_element;
> }
> };
>
> Am I missing something?
>
> 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/ |
> |________________________________________________________________|
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk