Flip Reference

Collection::iterator Class Reference

Declared in

flip/Collection.h

template <class T> class Collection
{
class iterator;
class const_iterator;
class reverse_iterator;
class const_reverse_iterator;
};

Collection::iterator satisfies the BidirectionalIterator C++ concept.

WARNING: Unlike the C++ standard library, when an element is erased from a container, and if iterating over the container before commit, the element is still present until the modification is commited, but the iterator is marked as removed.

Template Parameters

T

The type of the elements. T must inherit from flip::Object

Member Types

value_type

T

reference

T &

pointer

T *

difference_type

std::ptrdiff_t

iterator_category

std::bidirectional_iterator_tag

Member Functions Synopsys

Miscellaneous

added

Returns true iff the iterator was added to the container.

removed

Returns true iff the iterator was removed to the container.

resident

Returns true iff the iterator was neither added or removed.

Member Functions

added

bool added () const;

Returns true iff the iterator was added to the container.

Note: When an object is moved between containers, then the destination iterator is considered as added while the object is considered as resident.

Example :

void  Observer::document_changed (Collection <Note> & notes)
{
   auto it = notes.begin ();
   auto it_end = notes.end ();
   for (; it != it_end ; ++it)
   {
      Note & note = *it;
      if (it.added () && note.resident ())
      {
         // the note was moved from one container to another
         // this is the destination container
      }
      if (it.removed () && note.resident ())
      {
         // the note was moved from one container to another
         // this is the source container
      }
   }
}

removed

bool removed () const;

Returns true iff the iterator was removed to the container.

Note: When an object is moved between containers, then the source iterator is considered as removed while the object is considered as resident.

void  Observer::document_changed (Collection <Note> & notes)
{
   auto it = notes.begin ();
   auto it_end = notes.end ();
   for (; it != it_end ; ++it)
   {
      Note & note = *it;
      if (it.added () && note.resident ())
      {
         // the note was moved from one container to another
         // this is the destination container
      }
      if (it.removed () && note.resident ())
      {
         // the note was moved from one container to another
         // this is the source container
      }
   }
}

resident

bool resident () const;

Returns true iff the iterator was neither added or removed.