using lambdas with function interpolation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

using lambdas with function interpolation

Panagiotis Zestanakis
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 performance-wise nor style-wise.  

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
Reply | Threaded
Open this post in threaded view
|

Re: using lambdas with function interpolation

MaelRL

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 performance-wise nor style-wise.  

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

Reply | Threaded
Open this post in threaded view
|

Re: using lambdas with function interpolation

Panagiotis Zestanakis
Thank you, Mael!

On Thu, Jun 14, 2018 at 4:48 PM Mael <[hidden email]> wrote:

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 performance-wise nor style-wise.  

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

Reply | Threaded
Open this post in threaded view
|

Re: using lambdas with function interpolation

MaelRL

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!

On Thu, Jun 14, 2018 at 4:48 PM Mael <[hidden email]> wrote:

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 performance-wise nor style-wise.  

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