string <-> null/bool implicit conversion

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 20 11:49:22 PDT 2015


On 08/20/2015 08:05 PM, H. S. Teoh via Digitalmars-d wrote:
> On Thu, Aug 20, 2015 at 01:50:11PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
> [...]
>> The main reason why it caused issues is this nice idiom:
>>
>> if(auto arr = someFunction())
>> {
>>     // use arr
>> }
>>
>> This would HAVE to be split out to two statements, and the arr variable
>> would be scoped outside of the if statement.
> [...]
>
> I wish the language would accept:
>
> 	if ((auto arr = someFunction()) !is null)
> 	{
> 		...
> 	}
>
> But IIRC, auto cannot be used except at the top level expression.
>...

You want !=, not !is.



More information about the Digitalmars-d mailing list