codereport / An-Algorithm-Library

A C++ algorithm library that extends the C++ standard algorithms found in <algorithm> & <numeric>
Boost Software License 1.0
22 stars 4 forks source link

const may not be correct afterall. #13

Open Sebanisu opened 3 years ago

Sebanisu commented 3 years ago

https://github.com/codereport/An-Algorithm-Library/blob/1a94a025ad0a187cc0fd39bb6bcbc9a5791338b2/src/aal/algorithm.hpp#L9

If the user is using a mutable lambda. Then they can't use the algorithm. So might need to remove const from these.

We might want to test a mutable lambda to see if it's working as expected. like [x=0] and ++x to make sure all the functions are correctly incrementing the value.

Though it should be fine I did some testing with compiler explorer. So I understand. The last function in the call will get the one that will increment because they are all pass by value.

https://github.com/codereport/An-Algorithm-Library/blob/1a94a025ad0a187cc0fd39bb6bcbc9a5791338b2/src/aal/algorithm.hpp#L19 Here we could forward the value to find. It might be better since any_of isn't actually calling the lambda.