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

Definition

The adaptor CGAL_Forward_circulator_from_container<C> is a class that provides a forward circulator for a container C as specified by the \stl. The iterators belonging to the container C are supposed to be at least forward iterators. The adaptor for bidirectional circulators is CGAL_Bidirectional_circulator_from_container<C> and for random access circulators it is CGAL_Random_access_circulator_from_container<C>. 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

CGAL_Forward_circulator_from_container<C>::Container
the template argument C.

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.

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 <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;

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;
}


Return to chapter: Circulators
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Mon, June 30, 1997.