Bug 11779 – pointer to slice is not an input range
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-19T13:25:38Z
Last change time
2019-11-19T16:04:49Z
Assigned to
No Owner
Creator
monarchdodra
Comments
Comment #0 by monarchdodra — 2013-12-19T13:25:38Z
As a rule thumb, when the type "S" is an input range, than so is "S*". Indeed, all of "S's primitives" can also be called using a pointer, EG:
S* p;
p.popFront(); //OK!
This works for *all* input ranges... except for slices. This is because the "slice range primitives" are actually non-member functions:
int[]* p;
p.popFront(); //DERP!
Error: template std.array.popFront does not match any function template declaration
I think, to be consistent with the "emulate a member primitive", that the range functions in std.array should also work on pointer to slice.
Comment #1 by peter.alexander.au — 2014-02-08T12:13:20Z
I don't think this can work with random access ranges. Pointers already define opIndex, so it can't be forwarded to pointee range.
I think the opposite of this request should be implemented: pointers should specifically *not* be ranges, ever.
(as an aside, I dislike how D uses . for pointer member access instead of ->, it's a massive hack in my opinion, and really unnecessary since pointers are rarely used in D).
Comment #2 by bugzilla — 2019-11-19T16:04:49Z
(In reply to Peter Alexander from comment #1)
> I think the opposite of this request should be implemented: pointers should
> specifically *not* be ranges, ever.
Yes, that would be better.