I wanted to test which method is faster to clean up a std::deque
using std::deque::cleaner
, std::deque::swap
and std::deque::pop_back
.
To do that I created a program that has:
- a function to test
Testit
and receive a lambda with the specific method; - a struct with the description of the method, a lambda with the method itself and the result;
When I run the program I've been got "bad_function_call".
What is wrong with the program and how can I fix it to make the struct/class works as expected with lambdas members?
Below you can see the important part of the program:
//Procedure to test. It receive a lambda with the method to clean the deque up.
int Testit(auto& fCleanUp_the_Container) {
(...)
deque<string> vdTEST; //deque to be tested
//Add elements to vdTEST
fCleanUp_the_Container(vdTEST);
(...)
}
struct dData {
//The Description and lMethodtoCleanUp will be initialize with the std::vector::emplace_back method.
dData(string Description, function<void(deque<string>& vdTEST)> lMethodtoCleanUp) {};
int Results = 0;
string Description;
function<void(deque<string>& vdTEST)> lMethodtoCleanUp;
};
int main () {
(...)
//upload the data to a vector;
vector<dData> dDt;
dDt.emplace_back("clear", [](deque<string>& vdTEST) {vdTEST.clear();}); //Using std::deque::clear
dDt.emplace_back("swap", [](deque<string>& vdTEST){deque<string> vdTMP; vdTEST.swap(vdTMP);}); //Using std::deque::swap
dDt.emplace_back("pop_back", [](deque<string>& vdTEST){while (!vdTEST.empty()) vdTEST.pop_back();}); //Using std::deque::pop_back
//running the test
for (int iIta=1; iIta != noofCycles; iIta++) {
cout << "\nCycle " << iIta << "...";
for (auto& iIt : dDt) //Test all members of dDt
iIt.Results += Testit(iIt.lMethodtoCleanUp);
}
(...)
}