| metaprogramming/conditional/cond-4.cc - Use of my_conditional - in the example from above. | Lecture 6 - slide 34 : 40 Program 5 |
// Using my_conditional instead of std:conditional, via a programmed syntactial embellishment Conditional.
#include <iostream>
#include <type_traits>
#include "conditional-def.cc"
// Conditional is a syntactial embellishment of the underlying conditional template:
template<bool B, typename T, typename F>
using Conditional = typename my_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
// ...
return 0;
}