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

Definition

The adaptor CGAL_Forward_circulator_from_iterator<I,T,Size,Dist> 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 CGAL_Bidirectional_circulator_from_iterator< I, T, Size, Dist> converts bidirectional iterators and CGAL_Random_access_circulator_from_iterator< I, T, Size, Dist> random access iterators. 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;

In addition all types required for circulators are provided.

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,
I cur);
a circulator c initialized to refer to the element *cur in a range [begin,end ). The circulator c contains a singular value if begin==end.

CGAL_Forward_circulator_from_iterator<I,T,Size,Dist> c ( CGAL_Forward_circulator_from_iterator<I,T,Size,Dist> d,
I cur);
a copy of circulator d referring to the element *cur. The circulator c contains a singular value if d does so.

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

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

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.

See Also

CGAL_Forward_container_from_circulator, CGAL_Forward_circulator_from_container.

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 <CGAL/basic.h>
#include <assert.h>
#include <vector.h>
#include <algo.h>
#include <CGAL/circulator.h>

typedef  vector<int>::iterator         I;
typedef  vector<int>::value_type       V;
typedef  vector<int>::size_type        S;
typedef  vector<int>::difference_type  D;
typedef  CGAL_Random_access_circulator_from_iterator<I,V,S,D> 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.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. 22 January 1999.