Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

Type deduction and substitution

Type deduction and substitution are closely related, but not exactly the same. Deduction is the process of guessing—What should the template type, or types, be in order to match the call? Of course, the compiler does not really guess, but applies a set of rules defined in the standard. Consider the following example:

template <typename T> void f(T i, T* p) {    std::cout << "f(T, T8)" << std::endl;}int i;f(5, &i);       // T == intf(5l, &i);      // ?

When considering the first call, we can deduce from the first argument that the T template parameter should be int. Thus, int is substituted for T in both parameters of the function. The template is instantiated as f(int, int*) and is an exact match for the argument types. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content