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

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

Thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.