Bartosz Milewski seems to like D more than C++ now :)

Jonathan M Davis jmdavisProg at gmx.com
Fri Sep 20 09:57:33 PDT 2013


On Friday, September 20, 2013 18:46:34 Szymon Gatner wrote:
> On Friday, 20 September 2013 at 16:38:29 UTC, Andrei Alexandrescu
> 
> wrote:
> > On 9/20/13 8:13 AM, 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.
> > 
> > Well you can't call popFront on any const range.
> 
> What is even the purpose of const ranges? It makes little sense
> imho. Why would GoF iterator be immutable? It is like trying to
> iterate over collection bu indexing but only having const int as
> index variable. If anything it only make sense to have ranges to
> const (abstraction over const_iterator).

If an object is const, then all of its members are const, which means that any 
ranges you get from its members will be const, making such ranges useless. But 
it still makes sense to iterate over such a range (in most cases, you care 
about the elements in the range, not the range itself). But since you can't 
iterate over the range (because it's const), you need to get a tail-const 
slice of it to iterate over instead. If you can do that, then const ranges 
aren't a huge problem. The problem is that making it so that you can get a 
tail-const slice of a const user-defined range is incredibly difficult. The 
compiler understands arrays, so it works there, but it doesn't work anywhere 
else. So, at this point, const and ranges don't play nicely at all.

- Jonathan M Davis


More information about the Digitalmars-d mailing list