template, implicit specialization?

Discussion in 'C++' started by Guest, Sep 18, 2005.

  1. Guest

    Guest Guest

    Hi everyone, I've got this pice of code:

    template <bool cond, typename A, typename B>
    struct Select{
    typedef A Result;
    };

    template <typename A, typename B>
    struct Select<false, A, B>{
    typedef B Result;
    };

    Select<false, char, float>::Result temp;

    What is the second template supposed to be? An implicit specialization? It's
    not an explicit one for sure.
    If anyone could explain me what happens ...it would be great. thanx
     
    Guest, Sep 18, 2005
    #1
    1. Advertising

  2. Guest

    persenaama Guest

    > What is the second template supposed to be?

    A partial specialization.

    > If anyone could explain me what happens ...it would be great. thanx


    What happens is that Select<false,char,float>::Result is float. For
    such trivial example it is equivalent of:

    float temp;

    The usefulness of such contruct becomes more apparent in more complex
    programs.
     
    persenaama, Sep 18, 2005
    #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. David B. Held
    Replies:
    2
    Views:
    483
    Rob Williscroft
    Oct 26, 2003
  2. Dave
    Replies:
    4
    Views:
    7,775
    pdixtl
    Jun 4, 2010
  3. pit3k
    Replies:
    8
    Views:
    378
    Victor Bazarov
    Feb 9, 2005
  4. Joseph Turian
    Replies:
    2
    Views:
    494
  5. Angel Tsankov
    Replies:
    12
    Views:
    790
    Angel Tsankov
    Jan 14, 2007
Loading...

Share This Page