The function
Wrapper and Template Inefficiencies
Consider the following line of code:
answer = ef(q);
What is ef
? It could be the name of a function. It could be a pointer to a function. It could be a function object. It could be a name assigned to a lambda expression. These all are examples of callable types. The abundance of callable types can lead to template inefficiencies. To see this, let’s examine a simple case.
First, let’s define some templates in a header file, as shown in Listing 18.6.
// somedefs.h#include <iostream>template <typename T, typename F>T use_f(T v, F f){ static int count = 0; count++; std::cout << " use_f count = " << count << ", &count = " << &count << std::endl; return ...
Get C++ Primer Plus 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.