[Issue 7177] $ should forward to length by default

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 21 14:32:10 PDT 2013


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



--- Comment #34 from timon.gehr at gmx.ch 2013-03-21 14:32:09 PDT ---
(In reply to comment #32)
> (In reply to comment #31)
> > Needing to state in the template constraint that a type supports syntax sugar
> > appears to be sub-optimal at best. (Whether or not it is used will usually be
> > an implementation detail.) IMO adding opDollar using UFCS makes the most sense.
> 
> I think the mistake here is the assumption that $ is syntax sugar.  opDollar is
> a function, and is not required to return length, otherwise we wouldn't be
> having this discussion.
> 
> A more semantically named trait would be hasEnd.

Ok. Still, a finite RandomAccessRange should always satisfy hasEnd.

opDollar is syntax sugar. I do not think there is a halfway decent API where
opDollar is not an alias to a more aptly named member.

For ranges, it is length, for dcollections, it might be end, etc.

If opDollar is not considered syntax sugar, you have:

auto end = m.opDollar();

However, why does it even make sense to make opDollar denote end? There is no
analogue for begin.

m[m.begin()..m.end()]
...
m[m.begin()..$]
...
uh.

-- 
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