Alex
Alex

Reputation: 77

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;});

Upvotes: 3

Views: 98

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477060

You can use lambdas for that:

std::equal(arr1, arr1 + 5, arr2, [](double a, double b) { return a == -b; });

Upvotes: 5

Related Questions