Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Applying a functor to CGAL iterator ranges.

Subject: CGAL users discussion list

List archive

[cgal-discuss] Applying a functor to CGAL iterator ranges.


Chronological Thread 
  • From: Ross Hemsley <>
  • To:
  • Subject: [cgal-discuss] Applying a functor to CGAL iterator ranges.
  • Date: Tue, 5 Feb 2013 17:19:26 +0100 (CET)

I am writing a class with a series of functions that work by applying
functors to an iterator range over a set of elements.


Example:

template< typename Iterator, typename Functor >
double mean(Iterator begin, Iterator end, Functor f)
{
    double sum   = 0;    
    int    count = 0 ;

    for (Iterator i=begin; i!=end; ++i)
    {
        sum += f(*i);
        ++count;
    }
}


However, I now want to use the "Triangulation_2::finite_vertices_iterator"
as the iterator, and I want to apply a functor that requires access to the
vertex_handle. - This is a problem because the algorithm above dereferences
the iterator and gives me a plain vertex: The problem is that dereferencing
the iterator that CGAL gives us causes us to lose information.

I'm looking for a solution that keeps the same input parameters (an iterator 
with '::value_type' that corresponds to the argument of the functor). 
But may work differently 'under the hood' - i.e. we have a special 
helper function "apply(f, x)" that applies a function to an 
iterator. I tried to use some dirty 'template magick' tricks to do this but 
the ideas I had require features that are only reliably available in C++11.

Any ideas?




Archive powered by MHonArc 2.6.18.

Top of Page