I am writing some tests for a class. I have multiple tests and each one creates its own MyObj. However, MyObj takes in a std::function<bool<T>>, and I don't want to create a lambda function with the same functionality every time I create MyObj. So instead of having this:
TEST1()
{
MyObj<double> myobj([&](double time) -> bool
{
time = myobj.doSomething();
// ... more functionality
});
}
TEST2()
{
MyObj<double> myobj([&](double time) -> bool
{
time = myobj.doSomething();
// ... more functionality
});
}
...
Rather I want to have the function defined once and reference it every time I have to create a new MyObj:
bool myFunc(double time)
{
time myobj.doSomething();
// ... more functionality
}
TEST1()
{
MyObj<double> myobj([&myFunc]()); // Something like this
}
TEST2()
{
MyObj<double> myobj(std::bind(&myFunc, myobj, std::placeholders::_1)); // Or something like this
}
So some things to note:
- Class
MyObj, all copy/reference constructors have been deleted. - Theres more functionality associated with myFunc which is why I don't want to repeat every time since there are numerous test cases.
- I need a reference to the
MyObjcreated in the actual function (myFunc).
Any help is appreciated. Thanks.
Aucun commentaire:
Enregistrer un commentaire