![]() |
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>
|
|
|
|
In addition all types required for circulators are provided.
|
| |||
|
a circulator c on an empty sequence.
| |||
|
| |||
|
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.
| |||
| |||
|
a copy of circulator referring to the element *cur.
The circulator c refers to a empty sequence
if does so.
| |||
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.
Container_from_circulator, Circulator_from_container, Circulator.
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.