Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++: Declare function inside of function call

Is it possible to pass a function definition as an arguement and if so what is the syntax for that? If it is not, what would be the reason? I would like to do something like:

double arr1[10], arr2[10];

std::equal(arr1, &(arr1[5]), arr2, (bool(*)(double a, double b){return a == -b;});
like image 201
Alex Avatar asked May 17 '26 10:05

Alex


1 Answers

You can use lambdas for that:

std::equal(arr1, arr1 + 5, arr2, [](double a, double b) { return a == -b; });
like image 85
Kerrek SB Avatar answered May 19 '26 23:05

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!