CGAL::Circulator_from_iterator<I>

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 on an empty sequence.


Circulator_from_iterator<I> c ( I begin, I end, I cur = begin);
a circulator c initialized to refer to the element *cur in a range [begin,end). The circulator c refers to a empty sequence if begin==end.


Circulator_from_iterator<I> c ( Circulator_from_iterator<I,T,Size,Dist> d,
I cur);
a copy of circulator d referring to the element *cur. The circulator c refers to a empty sequence if d does so.

Operations

The adaptor conforms to the requirements of the respective circulator category. An additional member function current_iterator() returns the current iterator pointing to the same position as the circulator does.

See Also

Container_from_circulator, Circulator_from_container, Circulator.

Example

The following program composes two adaptors - from an iterator to a circulator and back to an iterator. It applies an STL sort algorithm on a STL vector containing three elements. The resulting vector will be [2 5 9] as it is checked by the assertions. The program is part of the CGAL distribution.

// file: examples/Circulator/circulator_prog1.C

#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 is a random access circulator 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 access circulator c over this array.