[Issue 5351] New: Add template mixin for Range Primitives using random access
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 14 09:29:01 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5351
Summary: Add template mixin for Range Primitives using random
access
Product: D
Version: D2
Platform: Other
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: Jesse.K.Phillips+D at gmail.com
CC: Jesse.K.Phillips+D at gmail.com
--- Comment #0 from Jesse Phillips <Jesse.K.Phillips+D at gmail.com> 2010-12-14 09:27:14 PST ---
This came form a post by Lars on how to remove the boilerplate if you already
have a random access interface:
To avoid the boilerplate, you could write a mixin that defines the
iteration primitives for you.
mixin template IterationFuncs()
{
int index;
bool empty() { return index == length; }
auto front() { return opIndex(index); }
void popFront() { ++index; }
// ... etc.
}
Then you'd just have to define opIndex() and length(), and the mixin does
the rest for you.
struct MyRange(T)
{
T opIndex(int i) { ... }
@property int length() { ... }
mixin IterationFuncs!();
}
(I haven't tested the code above, so it probably has bugs, but you get
the point.)
-Lars
--
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