Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-10-08 01:39:22

On 10/8/07, Joel de Guzman <joel_at_[hidden]> wrote:
> There's no way to detect the signature
> of a template function (the operator()):

Perhaps you don't need this. You only need to check if the template
function operator() matches one signature in the Signatures set.

I have found this nice (and very small) code from Paul Mensonides that
seems to works (at least for me)

The limitation is that you have to specify the type of the function,
but in our case is not a problem because we have a finite set called
'Signatures' among which to choose the operator() type.

As you can see from his testing example:

truct X {
    void operator()(void) {

struct Y { };

struct Z {
    template<class T> T operator()(T v) const {
        return v;

int main(void) {
        << has_function_call<void (X::*)(void)>::value << '\n'
        << has_function_call<void (Y::*)(void)>::value << '\n'
        << has_function_call<int (Z::*)(int) const>::value << '\n';
    return 0;

It is possible to check against any operator() given that you now the
signatures you are looking for. Now the challange is, given a function
obect of class F, to forge a way to loop across Signatures, that are
function signatures,

void (void)
void (void)
int (int) const

transform in the corresponding member signatures of class F

void (F::*)(void)
void (F::*)(void)
int (F::*)(int) const

And check each one with has_function_call() until a match is found or
return an error otherwise.

Easier to say then to do ;-)


Boost list run by bdawes at, gregod at, cpdaniel at, john at