Peter_B, thanks for this explanation. It didn't come to my mind that the reference might be the problem. I have played around with the bar() signature, making it const or not, making the parameter to bar const or not, but never thought about the reference. Then I changed bar() to take an int, and that worked, leaving me even more confused.

superbonzo, I was so concentrated on the member function that the lambda you propose didn't come to my mind.

Thanks for your contributions,
Richard