Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: thread about the pros and cons of lambdas, but more about cons
Date: Sat, 28 Sep 2024 04:06:40 -0700
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <86setk3um7.fsf@linuxsc.com>
References: <20240925195423.00007ecc@yahoo.com> <871q17idqr.fsf@bsb.me.uk> <87v7yjgyfq.fsf@bsb.me.uk> <8634lm73jc.fsf@linuxsc.com> <20240926202050.00002d46@yahoo.com> <86tte25n9h.fsf@linuxsc.com> <20240927162713.000060ea@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Sat, 28 Sep 2024 13:06:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8f5b490802ead3c9705b43cb022c8c76"; logging-data="1286855"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AUwp/IOHK0/4jOMe9Bcc3EKLfg8zHy1k="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:GPveKGiz46rTaTe5qTeFyoo7j14= sha1:OF4AGWCkWFrTt/033Px18RGWWr8=
Xref: csiph.com comp.lang.c++:120430
Michael S writes:
> On Thu, 26 Sep 2024 10:38:02 -0700
> Tim Rentsch wrote:
>
>> Michael S writes:
>>
>>> On Thu, 26 Sep 2024 10:01:11 -0700
>>> Tim Rentsch wrote:
>>>
>>>> Ben Bacarisse writes:
>>>>
>>>>> Ben Bacarisse writes:
>>>>>
>>>>>> ... You can,
>>>>>> instead, do this (untested):
>>>>>
>>>>> I should have tested! Of course you have to change the capture
>>>>> (at least for core) from '=' to '&':
>>>>>
>>>>>> #include
>>>>>>
>>>>>> int floodfill4(
>>>>>> unsigned char *grey,
>>>>>> int width, int height,
>>>>>> int x, int y,
>>>>>> unsigned char target, unsigned char dest)
>>>>>> {
>>>>>> if (width < 1 || height < 1)
>>>>>> return 0;
>>>>>> if (x < 0 || x >= width || y < 0 || y >= height)
>>>>>> return 0;
>>>>>>
>>>>>> size_t w = width, h = height;
>>>>>> if (grey[y*w+x] != target)
>>>>>> return 0;
>>>>>>
>>>>>> std::function core;
>>>>>> core = [&] (size_t x, size_t y) {
>>>>>
>>>>> Corrected-----^
>>>>
>>>> Why do you think [&] should be used instead of [=]?
>>>
>>> Compiler says that otherwise 'core' captures itself before it
>>> properly initialize.
>>> And indeed, it does not work (Segmentation fault).
>>
>> Ahh. A chicken and egg problem. I sidestepped that by initializing
>> 'core' as part of its declaration (as my other response to Ben
>> shows).
>>
>> No compiler warning, but I didn't try running it.
>
> It does not make any difference. The same crash as before.
Yes, not surprising.
> BTW, I am surprised that your compiler issues no warning.
Probably just an old compiler. I'm not up-to-date with what's
going on with C++ so there isn't much incentive to upgrade.
Trying again with clang I do get a warning.