C++ Logo

std-discussion

Advanced search

Re: Possible defect: unneeded const in lambda capture

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 29 Aug 2019 21:40:20 +0300
On Thu, 29 Aug 2019 at 21:35, Roman Odaisky via Std-Discussion
<std-discussion_at_[hidden]> wrote:
> > Such plausible cases have been explained before when this matter has come
> > up. Transformation from a loop to an algorithm that uses a lambda was the
> > original motivation.
>
> Certainly the user would use a [&] lambda for that? And if the nature of the
> algorithm is such that the lambda is stored somewhere and can outlive its
> calling scope, necessitating storage of captured values, that's precisely the
> use case I started with, which takes advantage of non-const members because
> they can be moved.

Would they? If the algorithm runs in multiple threads, they might want
a copy and don't
really care whether the lambda can or can't be moved from, because
it's copied into multiple
threads.

Received on 2019-08-29 13:42:37