From a correctness/standard standpoint, that is of course OK. Going beyond that, this question is largely opinion-based.
Lambdas are one of the many tools in C++. They add another layer of structure between "copy-paste for reuse" (code smell) and "extract it into a function". I personally enjoy function-local lambdas for exactly the listed purpose: You are reusing a small piece of code that is only meaningful within this function scope.
There are arguments to be made that it should still be its own function (because all your functions are 5 lines or shorter, right? Well, I doubt it...). In particular, if you ever want to reuse that lambda code, it should definitely be its own function. But before that, it is worth considering the benefit of having this code right there next to where it is used, instead of a screen or more of scrolling away. Also, both approaches give a name to the operation, but the lambda requires less overhead to write (e.g. private member function bloat). On the same page, adding a private member function to a header triggers recompiles, adding a lambda within the .cpp
does not.
In the end, consider what would make the code most readable. If the difference in code clarity between using a lambda or extracting it into a function is minute (not unlikely), then the convenience of writing the code starts to matter, for which the above considerations come into play.
As for testing, it depends on how fine-grained you want to test. Does a lambda expression like return a && b && (a == b);
really need a test? Would you test it if it was just used inline (i.e. not extracted as lambda or function)? At some point it becomes a waste of time, but determining that point is impossible in a SO answer.
bar
into a separate function so it would be possible to properly test it. – Sitra