How it works...

Class template type deduction is a new feature added in C++17 that provides the ability to deduce the type of a template class from its constructor. Suppose we have the following class template:

template<typename T>class the_answer{public:    the_answer(T t)    {        show_type(t);    }};

As shown in the preceding code snippet, we have a simple class template that takes a type T during construction and uses a show_type() function to output whatever type it is given. Before C++17, this class would have been instantiated using the following:

int main(void){    the_answer<int> is(42);}

With C++17, we can now instantiate this class as follows:

int main(void){    the_answer is(42);}

The reason this works is that the constructor of the class takes ...

Get Advanced C++ Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.