As we know, comparing two matching string literals can result in equality:
"hello" == "hello" //could be true or false
Does the same hold for lambdas:
[](){} == [](){} //false - guaranteed?
Is the compiler free to evaluate this as it pleases, or is it guaranteed that it will evaluate to false
? Is it legal? What does the above actually compare?
You cannot compare lambdas for equality. What you see in that little snippet is the lambdas being converted to function pointers and then the function pointers are compared. There are no guarantees that those function pointers are or are not the same, which means the result can be either true
or false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With