<div class="gmail_quote">On Mon, Jul 19, 2010 at 03:03, Robert Jacques <span dir="ltr"><<a href="mailto:sandford@jhu.edu">sandford@jhu.edu</a>></span> wrote:<br><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
A well designed opDollar is still an enhancement request: <a href="http://d.puremagic.com/issues/show_bug.cgi?id=3474" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=3474</a>. </blockquote><div><br>Ah, OK.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">However, there is a hack to get $ to return a value. Unfortunately, I've lost that newsgroup post.<br>
<br></blockquote><div>I got some May discussion about ^ and $ and a thread about opDollar for multidimensional arrays, but couldn't find any concrete things on opDollar. Strange, I thought that was part of DMD for a dozen releases. I guess, I'm wrong, then :)<br>
<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Memory got me this code snippet:<br>
<br>
<br>
struct Bar {<br>
int opIndex(int i) { writeln(i); return i; }<br>
<br>
}<br>
int __dollar() { return 5;}<br>
<br>
<br>
void main(string[] args) {<br>
Bar b;<br>
b[$];<br>
}<br>
</blockquote></div><br>It works, but in this case $ is global symbol, defined outside Bar. If I put it inside the struct, the compiler complains about __dollar being undefined.<br><br>Oh well, I'll push slices away from now, and use drop. Too bad, that would have make some parts more elegant.<br>
<br>Thanks Robert,<br><br><br> Philippe<br><br><br><br>