Boost logo

Boost :

Subject: [boost] determine first arg of callable
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2013-05-15 04:35:30


I need some help to extract the type of a callable which is passed as
argument to the ctor of X.

struct X
{
  template< typename Fn >
  X( Fn fn) {
       ... code which evaluates Fn and extracts the type of the first arg
of Fn
   }
};

void f( int) {...}

struct A
{
   void operator()( char) {...}
   void g( string) {... }
};

The code should evaluate in the ctor to the arguments of the callables:

A a;
X x1( f); -> int
X x2( a); -> char
X x3( bind( & A::g, a, _1) ); -> string

I could overload the ctor of X for function pointers:

  template< typename Arg >
  X( void(*fn)( Y< Arg > &) ) {...}

but how to deal with the other two callable types? result_of and
function_traits did not work for me.

Oliver


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk