I'm doing a little research for a course on which computing speed over collections on different cpu types. I'm writing my tests in C++ (bad choice as I started with the language three weeks ago) and I'm trying to measure the amount of clock ticks.
I thought I'd implement an arbitrary map (yes, yes, transform) function first. For some reason I decided to encapsulate the functions I'm writing in different classes. I first tried making a function that takes an arbitrary collection, but that didn't work, so I thought of making a function that takes two iterator pointers, so I'm currently having problems with this:
.h
#include <vector>
#include <map>
#include <ctime>
using namespace std;
class MapTests {
public:
static unsigned long halve(unsigned long in);
template <class InputIter>
static clock_t getHalveTest(InputIter begin, InputIter end);
};
.cpp
#include "MapTests.h"
unsigned long MapTests::halve(unsigned long in){ return in/2; }
template<class InputIter>
clock_t MapTests::getHalveTest(InputIter begin, InputIter end) {
vector<unsigned long> store = {};
auto beginTime = clock();
transform(begin, end, store, &MapTests::halve);
return clock()-beginTime;
}
I'm still planning on making a seperate function for std::map, but this is what I was planning to use for list, vector, array and such.
When I try to compile and print the clock ticks for the forward_list I get this monster of an error:
Undefined symbols for architecture x86_64: "unsigned long MapTests::getHalveTest*> >(std::__1::__forward_list_iterator*>, std::__1::__forward_list_iterator*>)", referenced from: _main in main.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
And I have no clue what I'm doing wrong here. I suspect I should do something with my template, but I don't know what.