template, implicit specialization?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    template, implicit specialization?

    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


  • persenaama

    #2
    Re: template, implicit specialization?

    > What is the second template supposed to be?

    A partial specialization.
    [color=blue]
    > If anyone could explain me what happens ...it would be great. thanx[/color]

    What happens is that Select<false,ch ar,float>::Resu lt is float. For
    such trivial example it is equivalent of:

    float temp;

    The usefulness of such contruct becomes more apparent in more complex
    programs.

    Comment

    Working...