Tuesday, November 21, 2017

C++17: User-Defined Deduction Guides

User-defined deduction guides do not have to be templates.


C++17: Class Template Argument Deduction

Class template argument deduction is done only when no template parameters are given.


C++17: User-Defined Deduction Guides

User-defined deduction guides look like constructors with return types declared. They are of the following general form:

template<{TemplateParameters>ClassTemplateName(ConstructorParameters) ->
                                             ClassTemplateSpecialization;

Reference: http://en.cppreference.com/w/cpp/language/class_template_argument_deduction

C++17: Automatic Deduction Guides – Overloaded Fictional Template Function Selection

The return type of the selected fictional template function is used as the deduced class template specialization.


C++17: Fictional Template Functions

Fictional template functions return the class template type.



C++17: Automatic Deduction Guides

The automatic deduction guides are the set of fictional template functions generated by the compiler.


C++17: Automatic Deduction Guides - Fictional Template Functions

C++17 creates three kinds of fictional template functions to represent class template constructors: 1) those based on actually declared constructors; 2) one based on a hypothetical default constructor; and 3) one based on a hypothetical copy constructor.