Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating null pointers from c++11 template parameter pack

I'm doing some metaprogramming and right now I need to test if a member function of a given type is callable with a given set of arguments, so I'm doing something like the following (which is heavily simplified by removing everything not important for this particular problem of course):

template<typename T, typename... Args>
struct argument_tester {
    struct base: public T { 
        using T::my_member; 
        no my_member(...){}
    };
    typedef decltype(static_cast<base*>(0)->my_member(*static_cast<Args*...>(0))) type;
    //verify return type
};

Of course it doesn't work with *static_cast<Args*...>(0), so my question is whether there is any way to unpack a parameter pack as dereferenced null pointers or if this is a case where I have to specialize for each number of arguments. And of course if there is a way how I would do that? I'm using gcc 4.6 in case that makes a difference for what's possible and what isn't.

like image 282
Grizzly Avatar asked May 22 '26 19:05

Grizzly


1 Answers

The ... unpack "operator" can be placed outside the expression, in which case the expression is expanded.

The solution would thus be, I think, (*static_cast<Args*>(0))....

EDIT: Following R. Martinho Fernandes' hint

typedef decltype(std::declval<base>().my_member(std::declval<Args>()...)) type;
like image 192
Matthieu M. Avatar answered May 24 '26 07:05

Matthieu M.