The adaptor Circulator_from_container<C> provides a circulator for an STL container 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 with a singular value.
| |||
| |||
a circulator c initialized to refer to the first element in
container, i.e. container.begin().
The circulator c contains a singular value if the
container is empty.
| |||
| |||
a circulator c initialized to refer to the element *i in
container.
|
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.
This program uses two adaptors, container 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_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; }