C++ Logo

std-discussion

Advanced search

Re: Possible defect: unneeded const in lambda capture

From: Roman Odaisky <roma_at_[hidden]>
Date: Thu, 29 Aug 2019 21:43:14 +0300
On Thursday, 29 August 2019 21:40:20 EEST Ville Voutilainen wrote:
> 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.

People who don't care won't be affected. What's the downside?

-- 
WBR
Roman.

Received on 2019-08-29 13:45:21