0

I have some problems about promotion traits

template<typename T1, typename T2>
class Promotion;

template<bool C, typename Ta, typename Tb>
class IfThenElse;

template<typename Ta, typename Tb>
class IfThenElse<true, Ta, Tb>
{
  public :
    typedef Ta ResultT;
};

template<typename Ta, typename Tb>
class IfThenElse<false, Ta, Tb>
{
  public :
    typedef Tb ResultT;
};

template<typename T1, typename T2>
class Promotion
{
  public :
    typedef typename IfThenElse< (sizeof(T1) > sizeof(T2)),
                                  T1,
                                  typename IfThenElse<(sizeof(T1) < sizeof(T2)),
                                  T2,
                                  void>::ResultT>::ResultT ResultT;
};

Why did they make the code of promotion looks like this

typename IfThenElse<(sizeof(T1) < sizeof(T2)),
                                  T2,
                                  void>::ResultT

but not

template<typename T1, typename T2>
class Promotion
{
  public :
    typedef typename IfThenElse< (sizeof(T1) > sizeof(T2)), T1, T2>::ResultT ResultT;
};

Thanks a lot

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by stereomatching
0

I don't know what the purpose of this code is but it looks like they want the following set of selection rules:
sizeof(T1) > sizeof(T2): ResultT = T1
sizeof(T1) = sizeof(T2): ResultT = void
sizeof(T1) < sizeof(T2): ResultT = T2

With the alternative you suggested the selection rules would be:
sizeof(T1) > sizeof(T2): ResultT = T1
sizeof(T1) <= sizeof(T2): ResultT = T2

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.