DGtal 1.4.0
|
Aim: hold any callable object (function, functor, lambda, ...) as a C(Unary)Functor model. More...
#include <DGtal/base/FunctorHolder.h>
Public Member Functions | |
template<typename Function , typename std::enable_if<!std::is_base_of< FunctorHolder, typename std::decay< Function >::type >::value, int >::type = 0> | |
FunctorHolder (Function &&fn) | |
Constructor. | |
template<typename... T> | |
auto | operator() (T &&... args) const -> decltype(Invoker< NeedDereference >::apply(this->myFunctor, std::forward< T >(args)...)) |
Invokes the stored callable object in a constant context. | |
template<typename... T> | |
auto | operator() (T &&... args) -> decltype(Invoker< NeedDereference >::apply(this->myFunctor, std::forward< T >(args)...)) |
Invokes the stored callable object in a mutable context. | |
void | selfDisplay (std::ostream &out) const |
Writes/Displays the object on an output stream. | |
constexpr bool | isValid () const |
Checks the validity/consistency of the object. | |
Private Attributes | |
FunctorStorage | myFunctor |
The callable object. | |
Aim: hold any callable object (function, functor, lambda, ...) as a C(Unary)Functor model.
FunctorStorage | Type used to store the given callable object. |
NeedDereference | true if the object must be dereferenced before calls. |
Given any type of callable object (function, functor and lambda) passed by value, reference or pointer, stores it in the most appropriate way so that the returned object is compatible with DGtal functor concept (concepts::CUnaryFunctor so far), and especially the boost::Assignable concept.
More precisely, the storage mode depends on the lifetime of the given object, deduced from its passing mode :
std::reference_wrapper
).std::shared_ptr
) so that the object lifetime matches the FunctorHolder lifetime.In both case, the returned object is copy/move constructible and copy/move assignable so that it can be used as a functor in all DGtal library.
std::move
. As a consequence, the type of the returned FunctorHolder cannot be guessed easily and the use of the auto
keyword is thus mandatory.More informations can be found in the dedicate module page about Using functions, functors and lambdas in DGtal .
Definition at line 152 of file FunctorHolder.h.
|
inlineexplicit |
Constructor.
Function | The type of the callable object (auto-deduced). |
fn | The callable object. |
Definition at line 172 of file FunctorHolder.h.
|
inlineconstexpr |
Checks the validity/consistency of the object.
Definition at line 225 of file FunctorHolder.h.
|
inline |
Invokes the stored callable object in a mutable context.
T | Arguments's types. |
args | The arguments. |
Definition at line 198 of file FunctorHolder.h.
References DGtal::functors::FunctorHolder< FunctorStorage, NeedDereference >::myFunctor.
|
inline |
Invokes the stored callable object in a constant context.
T | Arguments's types. |
args | The arguments. |
Definition at line 186 of file FunctorHolder.h.
References DGtal::functors::FunctorHolder< FunctorStorage, NeedDereference >::myFunctor.
|
inline |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
Definition at line 209 of file FunctorHolder.h.
References DGtal::functors::FunctorHolder< FunctorStorage, NeedDereference >::myFunctor.
|
private |
The callable object.
Definition at line 157 of file FunctorHolder.h.
Referenced by DGtal::functors::FunctorHolder< FunctorStorage, NeedDereference >::operator()(), DGtal::functors::FunctorHolder< FunctorStorage, NeedDereference >::operator()(), and DGtal::functors::FunctorHolder< FunctorStorage, NeedDereference >::selfDisplay().