just an idea (!! operator)

Alex Rønne Petersen alex at lycus.org
Thu Jul 12 10:35:04 PDT 2012


On 12-07-2012 19:32, Andrei Alexandrescu wrote:
> On 7/12/12 12:24 PM, Daniel Murphy wrote:
>> "Jonas Drewsen"<jdrewsen at nospam.com> wrote in message
>> news:zwtvliaunccmtwmabxfz at forum.dlang.org...
>>>
>>> auto a = foo ?? new Foo();
>>>
>>> is short for:
>>>
>>> auto a = foo is null ? new Foo() : foo;
>>>
>>> /Jonas
>>>
>>
>> Yeah, I've been planning to try and get this into D one day. Probably
>> something like:
>> (a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
>
> gcc used to have that extension and they dropped it...
>
> Andrei
>

But on the other hand, C# has had it from day one and it's still widely 
used and encouraged today: 
http://msdn.microsoft.com/en-us/library/ms173224(v=vs.110).aspx

I find it to be a useful little feature when I have to deal with 
possibly-null values.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d mailing list