

Dear All,
Does anyone know any way to directly pass a lambda as a functor to an interpolation function? For example, the signature of the linear interpolation function: template < class ForwardIterator, class Functor> typename Functor::result_type::first_type linear_interpolation(ForwardIterator first, ForwardIterator beyond, const typename std::iterator_traits<ForwardIterator>::value_type:: second_type& norm, Functor function_value) requires Functor to provide a type Functor::result_type. This makes it impossible to pass a raw lambda. Of course one could wrap the lambda with e.g. std::function, but in many cases this is not optimal performancewise nor stylewise.
Is there any other way to pass a raw lambda that I am not aware of? If not, are there any plans to support lambdas in future releases?
Best, Panos


Hello,
The simplest to keep your lambda is probably to modify the CGAL
function: replacing the instances of ::result_type in linear_interpolation()
by
typename boost::result_of<ValueFunctor(typename
std::iterator_traits<ForwardIterator>::value_type::first_type)>::type::first_type
will make it work with lambdas as well as more traditional
inputs.
I'll make a patch for CGAL to use result_of in the Interpolation
package.
Best,
Mael
On 06/14/2018 12:54 PM, Panagiotis
Zestanakis wrote:
Dear All,
Does anyone know any way to directly pass a lambda as a
functor to an interpolation function?
For example, the signature of the linear interpolation
function:
template < class ForwardIterator, class Functor>
typename Functor::result_type::first_type
linear_interpolation(ForwardIterator first, ForwardIterator beyond,
const typename
std::iterator_traits<ForwardIterator>::value_type::
second_type& norm,
Functor function_value)
requires Functor to provide a type Functor::result_type. This
makes it impossible to pass a raw lambda.
Of course one could wrap the lambda with e.g.
std::function, but in many cases this is not optimal
performancewise nor stylewise.
Is there any other way to pass a raw lambda that I am not
aware of?
If not, are there any plans to support lambdas in future
releases?
Best,
Panos


Thank you, Mael!
Hello,
The simplest to keep your lambda is probably to modify the CGAL
function: replacing the instances of ::result_type in linear_interpolation()
by
typename boost::result_of<ValueFunctor(typename
std::iterator_traits<ForwardIterator>::value_type::first_type)>::type::first_type
will make it work with lambdas as well as more traditional
inputs.
I'll make a patch for CGAL to use result_of in the Interpolation
package.
Best,
Mael
On 06/14/2018 12:54 PM, Panagiotis
Zestanakis wrote:
Dear All,
Does anyone know any way to directly pass a lambda as a
functor to an interpolation function?
For example, the signature of the linear interpolation
function:
template < class ForwardIterator, class Functor>
typename Functor::result_type::first_type
linear_interpolation(ForwardIterator first, ForwardIterator beyond,
const typename
std::iterator_traits<ForwardIterator>::value_type::
second_type& norm,
Functor function_value)
requires Functor to provide a type Functor::result_type. This
makes it impossible to pass a raw lambda.
Of course one could wrap the lambda with e.g.
std::function, but in many cases this is not optimal
performancewise nor stylewise.
Is there any other way to pass a raw lambda that I am not
aware of?
If not, are there any plans to support lambdas in future
releases?
Best,
Panos


Please see this pull request
for the patch on the whole Interpolation package.
Best,
Mael
On 06/15/2018 11:45 AM, Panagiotis
Zestanakis wrote:
Thank you, Mael!
Hello,
The simplest to keep your lambda is probably to modify
the CGAL function: replacing the instances of ::result_type
in linear_interpolation() by
typename boost::result_of<ValueFunctor(typename
std::iterator_traits<ForwardIterator>::value_type::first_type)>::type::first_type
will make it work with lambdas as well as more
traditional inputs.
I'll make a patch for CGAL to use result_of in the
Interpolation package.
Best,
Mael
On
06/14/2018 12:54 PM, Panagiotis Zestanakis wrote:
Dear All,
Does anyone know any way to directly pass a lambda
as a functor to an interpolation function?
For example, the signature of the linear
interpolation function:
template < class ForwardIterator, class Functor>
typename Functor::result_type::first_type
linear_interpolation(ForwardIterator first, ForwardIterator beyond,
const typename
std::iterator_traits<ForwardIterator>::value_type::
second_type& norm,
Functor function_value)
requires Functor to provide a type
Functor::result_type. This makes it impossible to pass
a raw lambda.
Of course one could wrap the lambda with e.g.
std::function, but in many cases this is not optimal
performancewise nor stylewise.
Is there any other way to pass a raw lambda that I
am not aware of?
If not, are there any plans to support lambdas in
future releases?
Best,
Panos

