samedi 30 mai 2015

How to use typename instead of typedef?

I have the following code snipper:

template <class T>
int foo(T (*f)()) {
    typedef T (*func)();
    typedef funct<T, func> F; //this line 
    auto result = F(f);
    auto result2 = bar<F>();

    return 0;
}

As you can see, we use typedef a function pointer on line 4. I want to remove first typedef. For example, I want to rewrite my code snippet, as:

template <class T>
int foo(T (*f)()) {
    typedef funct<T, typename f> F; //this line 
    auto result = F(f);
    auto result2 = bar<F>();

    return 0;
}

But, of course, there is a error.

Main purpose of this action is to simplify my code.

Aucun commentaire:

Enregistrer un commentaire