I have a class that holds various algorithms:
class Algorithm{
Algorithm()=delete;
public:
template <typename IntegerType>
static IntegerType One(IntegerType a, IntegerType b);
template <typename IntegerType>
static IntegerType Two(IntegerType a, IntegerType b);
template <typename IntegerType>
static IntegerType Three(IntegerType a, IntegerType b);
// ...
};
They can be called the following way:
int main(){
Algorithm::One(35,68);
Algorithm::Two(2344,65);
//...
}
Now I want to make a function that will take any "Algorithm" function and perform the same steps before and after calling that function.
Here is what I have:
template <typename IntegerType>
void Run_Algorithm(std::function<IntegerType(IntegerType,IntegerType)>fun, IntegerType a, IntegerType b){
//... stuff ...
fun(a,b);
//... stuff ...
return;
}
When I try to call the function like this:
Run_Algorithm(Algorithm::One,1,1);
The error I get is:
cannot resolve overloaded function ‘One’ based on conversion to type ‘std::function<int(int, int)>’
How can I go about setting up a generic routine, that takes the desired algorithm as a parameter?
EDIT:
This solution worked as desired.
It looks like this:
template <typename IntegerType>
void Run_Algorithm(IntegerType(*fun)(IntegerType, IntegerType), IntegerType a, IntegerType b){
//... stuff ...
fun(a,b);
//... stuff ...
return;
}