Boost logo

Boost Users :

Subject: [Boost-users] [type_traits][function_traits] generic way of obtaining argument of *both* a function and function object
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-09-06 17:48:36


Hi,

 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?

Thanks,
Alfredo



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net