If Statement with Declaration

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 4 13:08:04 PDT 2016


On 04.11.2016 21:03, Andrej Mitrovic wrote:
> On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
>>
>> So I was thinking of a way of extending if statements that have
>> declarations. The following being as example of the current use of if
>> statements with declarations:
>>
>>     if(int* weDontPollute = someFunc())
>>     {
>>          // use weDontPollute
>>     }
>>
>> That's great and all, but it only works by checking if the variable
>> evaluates to true or false. Which is fine for a pointer but otherwise
>> useless for anything else, like integers where zero is usually valid
>> input (index for array).
>
> This is already possible in library code. See here:
> https://github.com/AndrejMitrovic/minilib/blob/510460ff1381f765a66aa3b8f8f6d7e95b4597b9/src/minilib/core/types.d#L88-L137
>

Not worth the IFTI-induced template bloat IMHO.


More information about the Digitalmars-d mailing list