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

Definition

The adaptor CGAL_Forward_circulator_from_iterator< I, T, Size, Dist> is a class that converts two iterators, a begin and a past-the-end value, to a forward circulator. The iterators are supposed to be at least forward iterators. The adaptor for bidirectional circulators is CGAL_Bidirectional_circulator_from_iterator< I, T, Size, Dist> and for random access circulators it is CGAL_Random_access_circulator_from_iterator< I, T, Size, Dist> . Appropriate const circulators are also available.

I is the appropriate iterator type, T its value type, Size the unsigned integral value to hold the possible number of items in a sequence, and Dist is a signed integral value, the distance type between two iterators of the same sequence.

#include < CGAL/circulator.h>

Types

typedef I iterator;
typedef T value_type;
typedef Size size_type;
typedef Dist difference_type;

Creation

CGAL_Forward_circulator_from_iterator< I, T, Size, Dist> c;
a circulator c with a singular value.

CGAL_Forward_circulator_from_iterator< I, T, Size, Dist> c ( I begin,
I end);
a circulator c initialized to refer to the element *begin in a range [begin,end ). The circulator c contains a singular value if begin==end.

CGAL_Forward_const_circulator_from_iterator< I, T, Size, Dist> c;
a const circulator c with a singular value.

CGAL_Forward_const_circulator_from_iterator< I, T, Size, Dist> c ( I begin,
I end);
a const circulator c initialized to refer to the element *begin in a range [begin,end ). The circulator c contains a singular value if begin==end.

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

CGAL_Bidirectional_circulator_from_iterator< I, T, Size, Dist> c;

CGAL_Bidirectional_const_circulator_from_iterator< I, T, Size, Dist> c;

CGAL_Random_access_circulator_from_iterator< I, T, Size, Dist> c;

CGAL_Random_access_const_circulator_from_iterator< I, T, Size, Dist> 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, iterators 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_prog1.C      */
/*  ------------------------------ */
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/circulator.h>

typedef CGAL_Random_access_circulator_from_iterator< 
    vector<int>::iterator,
    vector<int>::value_type,
    vector<int>::size_type,
    vector<int>::difference_type
> 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.begin(), v.end());
    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;
}

Another example usage for this adaptor are random access circulators over the built-in C arrays. Given an array of type T* with a begin pointer b and a past-the-end pointer e the adaptor CGAL_Random_access_circulator_from_iterator< T*, T, size_t, ptrdiff_t> c( b,e) is a random circulator c over this array.


Next: Class declaration of CGAL_..._circulator_from_container<C>
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. Mon, June 30, 1997.