Subject: Re: [boost] [Fit] formal review starts today
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2016-03-03 21:14:04
On 03/03/2016 05:43 PM, Louis Dionne wrote:
> Steven Watanabe <watanabesj <at> gmail.com> writes:
>> On 03/03/2016 04:43 AM, Vicente J. Botet Escriba wrote:
>> 32: // Capture lvalues by reference and rvalues by value.
>> The default should be to capture everything by value.
>> Capturing by reference is potentially dangerous, and
>> switching based on whether the argument is an lvalue
>> is even more so.
> I've implemented the same thing in Hana, so I had to make the same design
> decision as Paul did at some point. I decided to be consistent with the rest
> of Hana, which is to capture by value.
> However, I am not sure that my decision in Hana was a wise one, and I am
> tempted to think that Paul's solution is actually the right one. Indeed,
> in most cases, `fit::capture` will be used as a temporary:
> some_alogrithm(..., fit::capture(variables...)(function));
> In this case, capturing by reference is harmless. <snip> Basically, my point is simply that
> saying "you should always capture by value" is naive in this context.
> Perhaps you're right, perhaps you're wrong, but in all cases this design
> choice is not an obvious one, at least not to me. Just my .02.
You have a point, and perhaps capturing by
reference makes sense. In fact, lambdas
do capture by reference by default, so
there is precedent for it. I do maintain,
however, that choosing whether to capture
by value based on l/r-valueness is definitely