M
Michael Klatt
I need to design a container similar to a std::set, but where the
stored objects may be modified via a non-const iterator. In some
cases the modification will effect the sort order.
Here's an example:
class Object { // an object from the database };
class Sorter { // functor that determines sort order for Objects };
template <class Obj, class Sort> class Set {};
Set<Object, Sorter> query;
Set<Object, Sorter>::Iterator it(query.begin());
while (it != query.end())
{
it->modify(); // uh oh, Set<> may be invalid now
}
In addition to this basic concept, is there a way to design Set<> so
that it automagically knows when a contained object has been changed
in a way that requires the set to be resorted?
stored objects may be modified via a non-const iterator. In some
cases the modification will effect the sort order.
Here's an example:
class Object { // an object from the database };
class Sorter { // functor that determines sort order for Objects };
template <class Obj, class Sort> class Set {};
Set<Object, Sorter> query;
Set<Object, Sorter>::Iterator it(query.begin());
while (it != query.end())
{
it->modify(); // uh oh, Set<> may be invalid now
}
In addition to this basic concept, is there a way to design Set<> so
that it automagically knows when a contained object has been changed
in a way that requires the set to be resorted?