January 2020
Intermediate to advanced
454 pages
11h 25m
English
Before C++17, you could provide non-type template arguments in a template, but you had to state the variable type in the definition, as shown in this example:
#include <iostream>template<int answer>void foo(){ std::cout << "The answer is: " << answer << '\n';}int main(void){ foo<42>(); return 0;}
The output is as follows:

In the preceding example, we create a template argument variable of the int type and output the value of this variable to stdout. In C++17, we can now do the following:
#include <iostream>template<auto answer>void foo(){ std::cout << "The answer is: " << answer << '\n';}int main(void){ foo<42>(); return 0; ...