The adaptor Circulator_from_container<C> provides a circulator for an STL container C of equal category as the iterator provided by the container. The iterator must be at least of the forward iterator category. The corresponding non-mutable circulator is called Const_circulator_from_container<C>.
The container type C is supposed to conform to the STL requirements for container (i.e. to have a begin() and an end() iterator as well as the local types reference, const_reference, value_type, size_type, and difference_type).
#include <CGAL/circulator.h>
All types required for circulators are provided.
| |||
a circulator c on an empty sequence.
| |||
| |||
a circulator c initialized to refer to the first element in
container, i.e. container.begin().
The circulator c refers to an empty sequence if the
container is empty.
| |||
| |||
a circulator c initialized to refer to the element *i in
container.
|
The adaptor conforms to the requirements of the corresponding 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_iterator, Circulator.
The following program composes two adaptors - from a container to a circulator and back to an iterator. It applies an STL sort algorithm on a STL vector with 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_prog2.cpp
#include <CGAL/basic.h> #include <cassert> #include <vector> #include <algorithm> #include <CGAL/circulator.h> typedef CGAL::Circulator_from_container< std::vector<int> > 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); 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; }