Constrained and Unconstrained Placeholders
Learn different types of placeholders.
We'll cover the following...
First, let me tell you about an asymmetry in C++14.
The big asymmetry in C++14
I often have a discussion in my classes that goes the following way. With C++14, we had generic lambdas. Generic lambdas are lambdas that use auto
instead of a concrete type.
Press + to interact
#include <iostream>#include <string>auto addLambda = [](auto fir, auto sec) {return fir+sec;};template <typename T, typename T2>auto addTemplate(T fir,T2 sec) {return fir+sec;}int main() {std::cout << std::boolalpha << '\n';std::cout << addLambda(1, 5) << " " << addTemplate(1, 5) << '\n';std::cout << addLambda(true, 5) << " " << addTemplate(true, 5) << '\n';std::cout << addLambda(1, 5.5) << " " << addTemplate(1, 5.5) << '\n';const std::string fir{"ge"};const std::string sec{"neric"};std::cout << addLambda(fir, sec) << " " << addTemplate(fir, sec) << '\n';std::cout << '\n';}
The generic lambda (at line 4 ...