Boost logo

Boost Users :

Subject: Re: [Boost-users] [type_traits][function_traits] generic way of obtaining argument of *both* a function and function object
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-09-13 21:30:47

Hi Alfredo,

I'm not aware of a ready-made Boost solution, but I wrote my own using boost::function_types
and other Boost goodies (see attached file).

Obviously, it only works if the functor's operator() is not overloaded or a template - basically
if you can take its address. (Otherwise the whole concept of an "nth parameter type" doesn't
make sense).


Date: Tue, 6 Sep 2011 14:48:36 -0700
From: alfredo.correa_at_[hidden]
To: boostusers_at_[hidden]
Subject: [Boost-users] [type_traits][function_traits] generic way of obtaining argument of *both* a function and function object


 Is there a uniform way to obtain the argument type of function object and of a function at the same time.

For example:

double fun(int a){ return ... ;}
struct A{
  double operator()(int a){ return ...;}
  typedef int argument_type; // or something like this (if needed)

template<class F> print_argument_type(F f){
   std::cout << typeid(
          argument_of<F>::type // or something like this ??
   ).name() << std::endl;

A a;
print_argument(fun); //should print "int"
print_argument(a); //should print "int"

Of course I am asking for something that at least works on objects in which operator() is not overloaded.
For functions we have function_traits< ... >::arg1_type (and other MPL variants) but I can not find a generic solution that also works for objects.

In other words I need something like boost/std::result_of but for the argument type; if this is not possible in general because of language limitations (e.g. because operator() can be overloaded) I am willing to accept any convention from out there that works both for functions and funciton objects. Just wanted to know what boost can say about this problem.

Maybe something that looks into the arguments of the member-function A::operator() via type_traits in case A is a class?


Boost-users mailing list

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at