October 2011
Beginner to intermediate
1200 pages
35h 33m
English
function Wrapper and Template InefficienciesConsider 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.
Listing 18.6. somedefs.h
// 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 ...
Read now
Unlock full access