Macro

CGAL_For_all

Definition

In order to write algorithms that work with iterator ranges as well as with circulator ranges we have to consider the difference of representing an empty range. For iterators this is the range [i,i), while for circulators it would be c == NULL, the empty sequence test. The function is_empty_range provides the necessary generic test which accepts an iterator range or a circulator range and says whether the range is empty or not.

#include <CGAL/circulator.h>

A macro CGAL_For_all( i, j) simplifies the writing of such simple loops as the one in the example of the function is_empty_range. i and j can be either iterators or circulators. The macro loops through the range [i, j). It increments i until it reaches j. The implementation looks like:

CGAL_For_all(i,j)

for ( bool _circ_loop_flag = ! ::CGAL::is_empty_range(i,j);
      _circ_loop_flag;
      _circ_loop_flag = ((++i) != (j)) 
)

Note that the macro behaves like a for-loop. It can be used with a single statement or with a statement block. For bidirectional iterators or circulators, a backwards loop macro CGAL_For_all_backwards( i, j) exists that decrements j until it reaches i.

See Also

iterator_distance, is_empty_range, Circulator_tag, Circulator_traits,
Assert_circulator_or_iterator, Circulator.