Typename pattern and syntax

I did the following struct

to extract the class member arguments:

template<typename...T>
class pack{};

template<typename...T>
struct getArgs{};
template<typename C,typename R,typename...Args>
struct getArgs<R(C::*)(Args...)>{using Type=pack<Args...>;};

      

But I'm not sure about the syntax to use it.

If I have a class func1

defined as:

template<typename T>
struct func1{
    constexpr T operator()(T x){return x+1;}
};

      

I was hoping it typename getArgs<typename func1<int>::operator()>::Type

would be equivalent pack<int>

, but my template argument keeps getting rejected as invalid.

So is typename getArgs<typename some_class<class_template_args>::member_function>::Type

not the correct syntax. Any help? Thank!

Edit: I would ideally like not to instantiate an object of the class func1

and have had success for other functions I created ...

eg. typename getN<1,pack<float,int> >::Type x;

works like float x;

where

template<std::size_t N,typename T,typename...Args>
struct getN_help:getN_help<N-1,Args...>{};
template<typename T,typename...Args>
struct getN_help<1,T,Args...>{using Type=T;};


template<std::size_t N,typename T>
struct getN;
template<std::size_t N,typename T,typename...Args>
struct getN<N,pack<T,Args...> >{
    using Type=pack<typename getN_help<N,T,Args...>::Type>;
};

      

+3


source to share


1 answer


In this line:

getArgs<typename func1<int>::operator()>::Type

      



typename func1<int>::operator()

is not a type, it is a function. You have to call a decltype()

pointer to it. Use operator&

to get a pointer to a member:

getArgs<decltype(&func1<int>::operator())>::Type

      

+1


source







All Articles