Original Post
I'm writing a benchmark for a template class, using function pointers to call different functions. I pass a function pointer to the tester function, which repeats the function over an array of data elements for a specified number of times. I want to pass a function pointer to a template function. Unfortunately, there is no generated object code for the templated version of the function. Is there any way I can request the compiler to explicitly create object code inside a c++ file for a template function with a specific set of template parameters? eg: blah.h blah.cpp
template <typename T>
void add(T *data) {
*data = (*(data + 1)) + (*(data + 2));
}
#include "blah.h"
// Line below does not work, of course.
void add<u64>(u64 *data);
void tests() {
// The line below causes a link error because there is no generated object code for add<u64>.
test(add<u64>, 3 * sizeof(u64), 100, 100);
}