[Issue 7177] $ should forward to length by default

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 29 15:50:57 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=7177



--- Comment #6 from Andrei Alexandrescu <andrei at metalanguage.com> 2011-12-29 15:50:54 PST ---
(In reply to comment #4)
> (In reply to comment #3)
> > Let me add that it's not impossible there are ranges that do have
> > multi-dimensional slicing but possibly no notion of "length". Sparse matrices
> > come to mind.
> 
> Yes. Another difference is that length is generally an integer. opDollar
> doesn't need to be, it could be any object. It can also be cheap to calculate
> opDollar but expensive to determine length.
> 
> I guess the question is, for what fraction of use cases will opDollar and
> length coincide?

Given a value x of type T, if the user is able to write both

x.length

and

x[0 .. $]

then it should be reasonable to expect the latter is interchangeable with x[0
.. x.length].

> It seems to be true for most ranges, which is interesting because they didn't
> even exist when this feature was first implemented -- it was designed for
> matrices -- yet they're now shaping us an important use of it. I don't think
> that there will be much application code that uses multi-dimensional opDollar,
> so it doesn't matter so much if those cases have a fair bit of boilerplate.
> 
> How commonly will people declare new ranges in application code?

Hard to estimate, but I suspect a fair amount (and we want to encourage that).
In STL defining an iterator is an act of courage, but we'd ideally hope that
people can easily define ranges that integrate with a variety of algorithms.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list