Metaprogramming question

I

Igor R.

Hello,

I'm trying to do the following: if and only if a metafunction is
defined for T, it's defined for wrapper<T> (i.e. for a type dependent
on T).
For some reason the following code is incorrect.
I'd appreciate any comment on this.

template<class T, class Enable = void>
struct metafunc;

template<>
struct metafunc<int>
{
typedef double type;
};

template<class T>
struct wrapper
{
typedef T type;
};

template<typename T>
struct metafunc<wrapper<T>, typename metafunc<T>::type>
{
typedef typename metafunc<T>::type type;
};

int main()
{
metafunc<wrapper<int> >::type t;
}
 
I

Igor R.

Ok, figured out the problem: "Enabled" template argument should be
"void" is the specialization. In short, std::enable_if would solve
this, as usually.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top