Navigation: Up, Table of Contents, Bibliography, Index, Title Page

Definition

The adaptor CGAL_Forward_circulator_from_container<C> provides a forward circulator for a container C as specified by the STL. The iterator belonging to the container C is supposed to be at least a forward iterator. The adaptor CGAL_Bidirectional_circulator_from_container<C> converts bidirectional iterators and CGAL_Random_access_circulator_from_container<C> random access iterators. Appropriate const circulators are also available.

C is the container type. The container is supposed to conform to the STL requirements for container (i.e. to have a begin() and an end() iterator as well as the local types value_type, size_type(), and difference_type).

#include <CGAL/circulator.h>

Types

typedef C Container;
typedef C::iterator
iterator;
typedef C::const_iterator
const_iterator;

In addition all types required for circulators are provided.

Creation

CGAL_Forward_circulator_from_container<C> c;
a circulator c with a singular value.

CGAL_Forward_circulator_from_container<C> c ( C* container);
a circulator c initialized to refer to the first element in container, i.e. container.begin(). The circulator c contains a singular value if the container is empty.

CGAL_Forward_circulator_from_container<C> c ( C* container, C::iterator i);
a circulator c initialized to refer to the element *i in container.
Precondition: *i is dereferenceable and refers to container.

CGAL_Forward_const_circulator_from_container<C> c;
a const circulator c with a singular value.

CGAL_Forward_const_circulator_from_container<C> c ( const C* container);
a const circulator c initialized to refer to the first element in container, i.e. container.begin(). The circulator c contains a singular value if the container is empty.

CGAL_Forward_const_circulator_from_container<C> c ( const C* container,
C::const_iterator i);
a const circulator c initialized to refer to the element *i in container.
Precondition: *i is dereferenceable and refers to the container.

The bidirectional and random access circulators have similar constructors. The default construction is shown here to present the adaptor names.

CGAL_Bidirectional_circulator_from_container<C> c;

CGAL_Bidirectional_const_circulator_from_container<C> c;

CGAL_Random_access_circulator_from_container<C> c;

CGAL_Random_access_const_circulator_from_container<C> c;

Operations

The adaptors conform to the requirements of the different circulator categories. An additional member function current_iterator() is provided that returns the current iterator that points to the same position as the circulator does.

See Also

CGAL_Forward_container_from_circulator, CGAL_Forward_circulator_from_iterator.

Example

This program uses two adaptors, container to circulators and back to iterators. It applies an STL sort algorithm on a STL vector with three elements. The resulting vector will be [2 5 9] as it will be checked by the assertions. The program is part of the CGAL distribution.

/*  circulator_prog2.C       */
/*  ------------------------------ */
#include <CGAL/basic.h>
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/circulator.h>

typedef CGAL_Random_access_circulator_from_container< vector<int> >  Circulator;
typedef CGAL_Random_access_container_from_circulator<Circulator> Container;
typedef Container::iterator Iterator;

int main() {
    vector<int> v;
    v.push_back(5);
    v.push_back(2);
    v.push_back(9);
    Circulator c( &v);
    Container  container( c);
    sort( container.begin(), container.end());
    Iterator i = container.begin();
    assert( *i == 2);
    i++;    assert( *i == 5);
    i++;    assert( *i == 9);
    i++;    assert(  i == container.end());
    return 0;
}


Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. 22 January 1999.