On Fri, Sep 20, 2013 at 05:13:45PM +0200, Joseph Rushton Wakeling wrote: > On 20/09/13 16:48, H. S. Teoh wrote: > >A container should not be confused with a range. That way leads to > >dragons. :-P (It's rather unfortunate that built-in arrays conflate > >the two, it leads to a lot of wrong code that works only with arrays > >but not with "real" ranges.) > > Built-in arrays are not _always_ ranges. Consider const(int[]) ... > as I found out recently, it's _not_ a range, because you can't > popFront on a const entity.
Which makes it even more confusing, since newbies would probably equate arrays (the container) with ranges from their frequent use in range examples. Perhaps it's more useful to think of T[] not as an array per se, but as a *slice* of the underlying array data which is managed by druntime. I think I'm OK with saying that arrays (i.e. the underlying data) are containers, while slices (what we think of today as "arrays") are ranges. Of course, the distinction isn't that clear cut, because appending to a "slice" creates a new array and returns a slice of that, so there's still some murky areas here. T -- Life would be easier if I had the source code. -- YHL
