Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          metaprogramming/conditional/cond-3.cc - Same - syntactically embellished.Lecture 6 - slide 34 : 40
Program 2

// Introducing a template alias (4ed, page 694) - a slight improvement.
// Conditional example - adapted from www.cplusplus.com. 

#include <iostream>
#include <type_traits>

// Conditional is a syntactical embellishment of the application of underlying conditional template:
template<bool B, typename T, typename F>
using Conditional = typename std::conditional<B, T, F>::type;                       

int main() {
  using namespace std;

  using A = Conditional<true,int,float>;                     // select int

  using B = Conditional<false,int,float>;                    // select float

  using C = Conditional<is_integral<A>::value,long,int>;     // select long - because type A is int

  using D = Conditional<is_integral<B>::value,long,int>;     // select int - because B is float

  // ...
}