if(;){} opinion

Chris Miller chris at dprogramming.com
Sun Feb 26 13:29:11 PST 2006


On Sun, 26 Feb 2006 13:43:55 -0500, Walter Bright  
<newshound at digitalmars.com> wrote:

>
> "Georg Wrede" <georg at nospam.org> wrote in message
> news:4401ECE3.4030207 at nospam.org...
>> Now consider:
>>
>>         if (Regexp m = std.regexp.search("abcdef", "b(c)d"))
>>         {
>>             writefln("[%s]", m.pre);      // prints [a]
>>             writefln("[%s]", m.post);     // prints [ef]
>>             writefln("[%s]", m.match(0)); // prints [bcd]
>>             writefln("[%s]", m.match(1)); // prints [c]
>>             writefln("[%s]", m.match(2)); // prints []
>>         }
>>
>> Flaunting this around (to both the original programmers, and also to
>> virgin victims), gave the same, _immediate_ comment from everybody: "Ah,
>> that's neat!"
>
> The idea behind m; was to be like foreach. What do the "victims" <g>  
> think
> of:
>
> if (auto m = std.regexp.search("abcdef", "b(c)d"))
>
> ?

That's what I was thinking, and perhaps it can be generalized to allow a  
declaration in any expression; allowing:
    while(auto foo = bar) { }
    baz(auto Foo f = new Foo); // RAII, f being destructed when baz()  
returns.
etc




More information about the Digitalmars-d mailing list