// Conditional example - adapted from www.cplusplus.com. Simple stuff. // Illustrates std::conditional and std:is_same. // Ilustrates using syntax (4ed, pages 167). #include #include int main() { // Establish aliases for selected types: using A = std::conditional::type; // select int using B = std::conditional::type; // select float using C = std::conditional::value, long, int>::type; // select long - because type A is int using D = std::conditional::value, long, int>::type; // select int - because B is float // Use established types: A a{}; // A variable of type A B b = [](B x) -> B{return x/2;}(10.0); // Use of type B in a lambda expressions, and its immediate call // Print info about types: std::cout << std::boolalpha; // print boolean values as false and true // (rather than 0 and 1) std::cout << "typedefs of int:" << std::endl; std::cout << "A: " << std::is_same::value << std::endl; // A: true std::cout << "B: " << std::is_same::value << std::endl; // B: false std::cout << "C: " << std::is_same::value << std::endl; // C: false std::cout << "D: " << std::is_same::value << std::endl; // D: true return 0; }