vincemansel/Cpp_Daily_Code — Issue #5: BingoSortTemplateTest: How to create a templatized function call with another templatized function
Author: vincemansel
Created: 2011-10-19 20:08:40+00:00
State: open

The original test routine (from softDetective) called RunExperiment which calls RunTest with a function pointer.

template
void RunExperiment(Vector &data, int sortCount, int runs, int expNum, string dataCondition);

void RunTest(Vector &data, void (fn)(Vector &, double), int runs, string name);

// in RunExperiment:
RunTest(v1, BingoSort, runs, "V1 " + dataCondition + ":");

If BingoSoft is not a templatized function, this works fine.

Let's define BingoSort as a templatized function:

template
void BingoSort(Vector &v, double d, int (cmpFn)(Type, Type) = OperatorCmp);

The above call to RunTest does not compile. There does not appear to be a facility make a function pointer
to a templatized function, generically.

Here is the workaround.

template
void RunTest1(Vector &data, int runs, string name);

RunTest1(v1, runs, "V1 " + dataCondition + ":");

In RunTest1, call the BingoSort templatized function directly:

BingoSort(testData, 1.0, BigStringsFirst);

Yes, RunTest1 is a templatized function taking a Type template.