Boost logo

Boost :

From: Ullrich Koethe (u.koethe_at_[hidden])
Date: 2001-07-11 14:36:00


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/      |
|________________________________________________________________|

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