Lumiera  0.pre.03
»edit your freedom«
_Fun< FUN, SEL > Struct Template Reference

#include "lib/meta/function.hpp"

Description

template<typename FUN, typename SEL = void>
struct lib::meta::_Fun< FUN, SEL >

Helper for uniform access to function signature types.

Extract the type information contained in a function or functor type, so it can be manipulated by metaprogramming. This template works on anything function like, irrespective if the parameter is given as function reference, function pointer, member function pointer, functor object, std::function or lambda. The embedded typedefs allow to pick up

  • Ret : the return type
  • Args: the sequence of argument types as type sequence Types<ARGS...>
  • Sig : the bare function signature type
  • Functor : corresponding Functor type which can be instantiated or copied.

This template can also be used in metaprogramming with enable_if to enable some definition or specialisation only if a function-like type was detected; thus the base case holds no nested type definitions and inherits from std::false_type. The primary, catch-all case gets activated whenever on functor objects, i.e. anything with an operator(). The following explicit specialisations handle the other cases, which are not objects, but primitive types (function (member) pointers and references).

Remarks
The key trick of this solution is to rely on decltype of operator() and was proposed 10/2011 by user «kennytm» in this stackoverflow.
Note
for a member pointer to function, only the actual arguments in the function signature are reflected. But if you bind such a member pointer into a std::function, an additional first parameter will show up to take the this pointer of the class instance.
Warning
this detection scheme fails when the signature of a function call operator is ambiguous, which is especially the case
  • when there are several overloads of operator()
  • when the function call operator is templated
  • on generic lambdas All these cases will activate the base (false) case, as if the tested subject was not a function at all. Generally speaking, it is not possible to probe a generic lambda or templated function, unless you bind it beforehand into a std::function with correct signature.
See also
FunctionSignature_test

Definition at line 108 of file function.hpp.

Public Types

using Functor = FUN
 
+ Inheritance diagram for _Fun< FUN, SEL >:
+ Collaboration diagram for _Fun< FUN, SEL >:

The documentation for this struct was generated from the following file: