[Issue 3474] New: PATCH: Implement opDollar for struct and class indexing operations
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 5 07:33:38 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3474
Summary: PATCH: Implement opDollar for struct and class
indexing operations
Product: D
Version: 2.036
Platform: Other
OS/Version: All
Status: NEW
Keywords: patch
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: clugdbug at yahoo.com.au
--- Comment #0 from Don <clugdbug at yahoo.com.au> 2009-11-05 07:33:37 PST ---
Created an attachment (id=491)
Patch against DMD2 svn 240.
The attached patch allows usage of $ inside opIndex and opIndexAssign in
structs and classes.
Any usage of $ becomes a call to an opDollar function.
If multi-dimensional indexing is possible, the $ symbol instantiates a template
called opDollar(int dim)().
x[ $-3, $-5, $-6] becomes x.opIndex(x.opDollar!(0)() - 3, x.opDollar!(1)() -
5, x.opDollar!(2)() -6);
Note that since opDollar is a template, it may return different types for
different indices...
As a convenience, if a class or struct ONLY supports single-dimension indexing,
a non-templated opDollar() can be used instead.
x[ $-5 ] can become x.opIndex( x.opDollar() - 5 );
(If a opDollar!(int n)() is available, it will be used instead. There's no
ambiguity: the compiler won't let you define both template and function
opDollar, since they both have no arguments).
Some implementation notes:
(1) $ is evaluated lazily for each dimension. x[4, $+3*$ - foo($), 6] will
only make one call to opDollar.
(2) BUG 3326: "$ in delegate literal causes Access Violation" does NOT apply to
this code. You can do all kinds of nasty stuff with $ and it seems to work.
(3) It is possible to nest multi-dimensional indexing. x[$-2, y[$-6, $-9], $-2]
works.
(4) I have NOT implemented $ inside opSlice(), opSliceAssign().
It could be done, but I believe those language features need work. They don't
permit multi-dimensional slicing. I think they should be removed, and the
functionality folded into opIndex.
(5) How it works:
x[ $-3, 5, $-6]= "abc" actually becomes:
x.opIndexAssign("abc", (auto __dollar = x.opDollar!(0)();, __dollar - 3), 5,
(auto __dollar = x.opDollar!(2)(); _dollar - 6)).
--
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