Skip to Content.
Sympa Menu

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

Subject: CGAL users discussion list

List archive

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


Chronological Thread 
  • From: Philipp Moeller <>
  • To: Ross Hemsley <>
  • Cc:
  • Subject: Re: [cgal-discuss] Applying a functor to CGAL iterator ranges.
  • Date: Tue, 05 Feb 2013 23:18:06 +0100
  • Organization: GeometryFactory

Ross Hemsley
<>
writes:

> 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?

I'm think you can write the necessary trait to detect if your functor is
callable with an lvalue of a certain type in C++03. There are a some
tricky parts when it comes to const qualification and behavior for
iterators where *it doesn't return a T&, but it should be possible.

On the other hand: Your functor can always cheat a
little. Triangulation_data_structure_2 is using Compact_container (this
is even publicly documented), which allows you to get an iterator/handle
from a value through Compact_container::s_iterator_to.



Archive powered by MHonArc 2.6.18.

Top of Page