Is it possible to accept two different types of lambda function as class members without knowing their template arguments ahead of time?
struct two_functors { std::function<???> a; std::function<???> b; ... };
Such that something like this would be possible:
void main(){ vector<two_functors> many_functors; int a = 2; int b = 3; double c = 4.7; double d = 8.4; two_functors add_and_subtract; add_and_subtract.a = [a, b](int x, int y){cout << x + y << endl;}; add_and_subtract.b = [c, d](double x, double y){cout << x - y << endl;}; two_functors multiply_and_divide; multiply_and_divide.a = [c, d](double x, double y){cout << x * y << endl;}; multiply_and_divide.b = [a, b](int x, int y){cout << x / y << endl;}; many_functors.push_back(add_and_subtract); many_functors.push_back(multiply_and_divide); for (auto functors : many_functors){ functors.a(); functors.b(); } }
two_functors
be a class template? Aren'tadd_and_print.a()
andadd_and_print.b()
incorrect without some arguments to pass asx
,y
, ands
?add_and_print
without having any kind of clue what it contains? Do you have an example of what you're trying to do?