#include <functional>
#include <iostream>
double function_a(double a, double b, double c, double d)
{
std::cout << "function_a(" << a << ", " << b << ", " << c << ", " << d << ")\n";
return a;
}
double function_b(double a, double b, int t, int u, double c)
{
std::cout << "function_b(" << a << ", " << b << ", " << t << ", " << u << ", " << c << ")\n";
return a;
}
struct second_func
{
second_func(int t, int u, double c) :t(t), u(u), c(c) {}
double operator()(double a, double b) { return function_b(a, b, t, u, c); }
int t;
int u;
double c;
};
void PerformAnalysis(std::function<double(double, double)> func)
{
func(4.0, 5.0);
}
int main()
{
auto first_func = [](double a, double b) { return function_a(a, b, 60.0, 2.1); };
// or:
// double c = 60.0;
// double d = 1.2;
// auto first_func = [=](double a, double b) { return function_a(a, b, c, d); };
PerformAnalysis(first_func);
PerformAnalysis(second_func(5, 90, 2.6));
}
I2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCmRvdWJsZSBmdW5jdGlvbl9hKGRvdWJsZSBhLCBkb3VibGUgYiwgZG91YmxlIGMsIGRvdWJsZSBkKQp7CiAgICBzdGQ6OmNvdXQgPDwgImZ1bmN0aW9uX2EoIiA8PCBhIDw8ICIsICIgPDwgYiA8PCAiLCAiIDw8IGMgPDwgIiwgIiA8PCBkIDw8ICIpXG4iOwogICAgcmV0dXJuIGE7Cn0KCmRvdWJsZSBmdW5jdGlvbl9iKGRvdWJsZSBhLCBkb3VibGUgYiwgaW50IHQsIGludCB1LCBkb3VibGUgYykKewogICAgc3RkOjpjb3V0IDw8ICJmdW5jdGlvbl9iKCIgPDwgYSA8PCAiLCAiIDw8IGIgPDwgIiwgIiA8PCB0IDw8ICIsICIgPDwgdSA8PCAiLCAiIDw8IGMgPDwgIilcbiI7CiAgICByZXR1cm4gYTsKfQoKc3RydWN0IHNlY29uZF9mdW5jCnsKICAgIHNlY29uZF9mdW5jKGludCB0LCBpbnQgdSwgZG91YmxlIGMpIDp0KHQpLCB1KHUpLCBjKGMpIHt9CgogICAgZG91YmxlIG9w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