Metaprogramming question

Discussion in 'C++' started by Igor R., Jan 3, 2012.

  1. Igor R.

    Igor R. Guest

    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;
    }
    Igor R., Jan 3, 2012
    #1
    1. Advertising

  2. Igor R.

    Igor R. Guest

    Ok, figured out the problem: "Enabled" template argument should be
    "void" is the specialization. In short, std::enable_if would solve
    this, as usually.
    Igor R., Jan 3, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Menard

    Metaprogramming question

    Steve Menard, Oct 6, 2006, in forum: Python
    Replies:
    2
    Views:
    237
    Georg Brandl
    Oct 6, 2006
  2. Replies:
    7
    Views:
    315
  3. Replies:
    3
    Views:
    343
    James Kanze
    Jul 16, 2008
  4. Replies:
    2
    Views:
    442
  5. Replies:
    5
    Views:
    317
    Kai-Uwe Bux
    Oct 12, 2008
Loading...

Share This Page