digitalmars.D.learn - Status of $ in class/struct?
- Nick Sabalausky (26/26) Mar 29 2011 I haven't been following the $/__dollar/opDollar/etc chronicles very
- Andrej Mitrovic (36/36) Mar 29 2011 I think its broken or something. It looks like its trying to find
- Jonathan M Davis (4/11) Mar 29 2011 It's not implemented yet: http://d.puremagic.com/issues/show_bug.cgi?id=...
I haven't been following the $/__dollar/opDollar/etc chronicles very
closely, and I can't find the answer in the docs, but I have simple
question:
Suppose I have this:
-------------------------------
class Foo
{
int[] data;
this(int[] data)
{
this.data = data;
}
ref T opIndex(size_t i)
{
return data[i];
}
}
void main()
{
auto foo = Foo([1,2,3,4,5]);
...
}
-------------------------------
Question:
Is there currently any way for Foo's author to make "foo[$-1]" work? If so,
how?
Mar 29 2011
I think its broken or something. It looks like its trying to find
__dollar in the current scope. Because this non-solution seems to
work:
module opDollarTest;
import std.stdio;
class Foo
{
int[] data;
this(int[] data)
{
this.data = data;
}
int opIndex(int a)
{
return data[a];
}
property
size_t length()
{
return data.length;
}
property
size_t opDollar()
{
return length;
}
}
void main()
{
auto foo = new Foo([1,2,3,4,5]);
size_t __dollar()
{
return foo.opDollar();
}
writeln(foo[$-1]);
}
Mar 29 2011
On 2011-03-29 19:29, Nick Sabalausky wrote:I haven't been following the $/__dollar/opDollar/etc chronicles very closely, and I can't find the answer in the docs, but I have simple question:[snip]Question: Is there currently any way for Foo's author to make "foo[$-1]" work? If so, how?It's not implemented yet: http://d.puremagic.com/issues/show_bug.cgi?id=3474 - Jonathan M Davis
Mar 29 2011









Andrej Mitrovic <andrej.mitrovich gmail.com> 