Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Metaprogramming question

Reply
Thread Tools

Metaprogramming question

 
 
Igor R.
Guest
Posts: n/a
 
      01-03-2012
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;
}
 
Reply With Quote
 
 
 
 
Igor R.
Guest
Posts: n/a
 
      01-03-2012
Ok, figured out the problem: "Enabled" template argument should be
"void" is the specialization. In short, std::enable_if would solve
this, as usually.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
template metaprogramming question nooneinparticular314159@yahoo.com C++ 5 10-12-2008 07:45 PM
(very) Simple Template Metaprogramming question stdlib99@googlemail.com C++ 2 09-10-2008 09:11 PM
Template metaprogramming question suman.nandan@gmail.com C++ 3 07-16-2008 07:24 AM
Metaprogramming question Steve Menard Python 2 10-06-2006 08:19 AM
Metaprogramming question PengYu.UT@gmail.com C++ 7 10-25-2005 09:40 AM



Advertisments