if(arr) now a warning

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 11:17:40 PDT 2015


On Friday, 10 April 2015 at 15:57:09 UTC, Andrei Alexandrescu 
wrote:
> On 4/10/15 6:26 AM, Meta wrote:
>> On Friday, 10 April 2015 at 12:42:47 UTC, Steven Schveighoffer 
>> wrote:
>>> Plus, adding arr.empty into object is kind of redundant. The 
>>> only
>>> reason we have arr.empty is so that it becomes a range.
>>>
>>> -Steve
>>
>> I find it extremely annoying to have to import std.array (or 
>> whatever
>> the correct module is) just to use .empty, .front and 
>> .popFront on
>> arrays. IMO they should all be in object.d.
>
> Yah, I was about to post the same. Range semantics are embedded 
> in the language enough to warrant this.
>
> Also empty should work for AAs.
>
>
> Andrei

I was going to suggest this myself, but I thought it would be too 
much. Having to import std.array to make std.algorithm work with 
slices is a bit of a curve ball for very new D programmers. They 
tend to do this...

import std.algorithm;

void main() {
     int[] arr = [1, 2, 3];

     arr = arr.map!(x => x * 2);
}

Then they get a compile time error and ask why it didn't work. It 
doesn't matter too much, but it is something you have to learn on 
your first day or so.


More information about the Digitalmars-d mailing list