The following are the signatures added for “SetFunctor”:
using ConstRefFunctionType = OutputImagePixelType (const Input1ImagePixelType &,
const Input2ImagePixelType &);
using ValueFunctionType = OutputImagePixelType (Input1ImagePixelType,
Input2ImagePixelType);
/** Set the pixel functor
*
* The functor defines an operation done per pixel.
*/
void SetFunctor( const std::function<ConstRefFunctionType> &f);
void SetFunctor( const std::function<ValueFunctionType> &f);
/** Set the pixel functor by a C function pointer
*
* The functor defines an operation done per pixel.
*/
void SetFunctor( ConstRefFunctionType *funcPointer);
void SetFunctor( ValueFunctionType *funcPointer);
/** Set the pixel functor by a "Functor Object"
*
* The functor defines an operation done per pixel. A single copy of
* the argument is created an used for all threads, so the functor
* must be concurrent thread-safe. The functor must a have an
* operator() method which accept arguments of Input1ImagePixelType,
* Input2ImagePixelType.
*/
template <typename TFunctor>
void SetFunctor( const TFunctor &functor);
So these signatures accept the C++ lambdas, C++ std::function
s, C-Style function pointers, and ITK Style functors. The one negative thing is that the last template SetFunctor
has no constraints so if “junk” is passed to it then an obscure compiler error message can be generated.
Also passing SetFunctor
C++ lambda, will use the templated signature. While the type of a lambda can be converted to a std::function
, the SetFunction
’ temple signature has higher priority than implicitly converting to std::function
. Because the template signature is used there is no enforcement of the specific arguments and return type for the lambda ( neither is there for the ITK Functors either ).
So this current approach has chosen flexibility over strong typing for the SetFunctor
argument. Is there any options or feedback from the modern C++ gurus around?