Why doesn't std.variant.visit automatically call the provided delegates?
Nemanja Boric via Digitalmars-d
digitalmars-d at puremagic.com
Sat Nov 5 03:25:30 PDT 2016
On Saturday, 5 November 2016 at 10:09:55 UTC, Adam D. Ruppe wrote:
> On Saturday, 5 November 2016 at 08:27:49 UTC, Nemanja Boric
> wrote:
>> [...]
>
> It calls the function... which returns a delegate, which you
> never called.
>
> This is one of the most common mistakes people are making: {}
> in D is a delegate, and () => is a delegate, therefore () => {}
> is a delegate that returns a delegate... usually NOT what you
> want.
>
> What you wrote is equivalent to writing
>
> delegate() callback(string s) {
> return delegate() {
> enforce(false);
> x = 2;
> };
> }
>
>
> Do not use the => syntax if there is more than one expression.
> You'll get what you want by simply leaving the => out:
>
>> [...]
Oh, God. Thanks, Adam, all clear!
Thanks!
More information about the Digitalmars-d
mailing list