Re: Obtaining function signature
In article <1171031407.137232.109670@s48g2000cws.googlegroups.com>,
<psujkov@gmail.com> wrote:
Hi everybody,
int f(int a, int b) { return a + b; };
is it possible to obtain this function signature - int (int, int) in
this case - for use in boost::function_traits ?
e.g. std::cout << "f's arity : " << boost::function_traits<*obtaining
signature from f()*>::arity << std::endl;
please no macro solutions - only C++ (Boost MPL maybe could be useful
- but still don't see how)
best regards, Paul Sujkov
template <class T> struct function_arity;
template <class R>
struct function_arity<R()> {static const int value = 0;};
// for N=1..N_max do
template <class R,class T1>
struct function_arity<R(T1)> {static const int value = 1;};
template <class R,class T1,class T2>
struct function_arity<R(T1,T2)> {static const int value = 2;};
// etc.
boost's preprocessor library can be used to automate this, but
you said no preprocessor stuff.
using boost function [which uses the preprocessor :)]
template <class F> struct function_arity
{
static const int value = boost::function<F>::arity;
};
but tr1::function does not provide this.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]