Definition

The adaptor Circulator_from_iterator<I> converts two iterators of type I, a begin and a past-the-end value, to a circulator of equal category. The iterator must be at least of the forward iterator category. The circulator will be mutable or non-mutable according to the iterator. Iterators provide no size_type. This adapter assumes std::size_t instead.

#include <CGAL/circulator.h>

Types

typedef I iterator;

In addition all types required for circulators are provided.

Creation

Circulator_from_iterator<I> c;
a circulator c with a singular value.


Circulator_from_iterator<I> 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.

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.

File: examples/Circulator/circulator_prog1.cpp
#include <CGAL/basic.h>
#include <cassert>
#include <vector>
#include <algorithm>
#include <CGAL/circulator.h>

typedef  std::vector<int>::iterator                  I;
typedef  CGAL::Circulator_from_iterator<I>           Circulator;
typedef  CGAL::Container_from_circulator<Circulator> Container;
typedef  Container::iterator                         Iterator;

int main() {
    std::vector<int> v;
    v.push_back(5);
    v.push_back(2);
    v.push_back(9);
    Circulator c( v.begin(), v.end());
    Container  container( c);
    std::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 Circulator_from_iterator< T*> c( b,e) is a random circulator c over this array.