Boost logo

Boost Users :

Subject: [Boost-users] [type_traits] deduce argument type of member function with function_traits
From: alfC (alfredo.correa_at_[hidden])
Date: 2011-09-03 01:29:57

Is function_traits the right way to extract the argument type of a member

In the following example I want to make the last line work. This will be
part of larger question, on how to deduce the argument type of operator()
for function objects in which operator() is not overloaded.

#include <typeinfo>
#include <iostream>
#include <boost/type_traits/function_traits.hpp>
#include <boost/type_traits/remove_pointer.hpp>

using namespace std;

double dsquare(double l){ return l*l; }
int isquare(int l){ return l*l; }

struct csquare_impl{
    int do(char c) const{
        return 'c';
csquare_impl csquare;

template<class F>
void test(F f){
    typename boost::function_traits<typename
boost::remove_pointer<F>::type>::arg1_type test_var;
    cout << typeid(test_var).name() << endl;

int main(){
    test(dsquare); // ok, prints "d"(double)
    test(isquare); // ok, prints "i"(int)
    test(csquare_impl::do); // not ok, want to print "c"(char)
    return 0;


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