2

I'm currently working on making a benchmark test harness for functions that will let me compare average run times for multiple functions with the same prototype. This is mostly just an academic exercise to learn more about template meta programming.

So here is the problem. I'm trying to create a template function that will let me call another function that is passed in as an argument using the values cast to their appropriate type from a vector that is also passed in.

I know that the run function will need specialization for position = 0 so that the recursion will stop and the function will be called. however currently I get a compile error when I try to extract the argument type telling me

error: non-template 'arg' used as template

However it is clearly defined as being a template.

Also I'm using code from here for the function traits.

template<typename Args>
struct function_traits;

template<typename R, typename ...Args>
struct function_traits< R(*)(Args... ) >
{
    static const size_t nargs = sizeof...(Args);
    typedef R result_type;
    template <size_t i>
    class arg
    {
        typedef typename std::tuple_element<i, std::tuple<Args...>>::type type;
    };
};

struct Argument
{
    char * data;
    int size;
};

template<size_t position,typename Func,typename... arguments>
function_traits<Func>::result_type run(vector<Argument> arglist,
                                       Func f,
                                       arguments... args)
{
    //compile error on this statement.
    typedef typename function_traits<Func>::arg<position>::type argtype;


    return process<position-1>(arglist,f,(argtype)(*arglist[position].data) ,args...);
}
Community
  • 1
  • 1
Robert F.
  • 63
  • 5

1 Answers1

1

Adding the template keyword seems to work for me.

typedef typename function_traits<Func>::template arg<position>::type argtype;

See this question for more details.

Community
  • 1
  • 1