opDollar and infinite slices on infinite ranges

Philippe Sigaud philippe.sigaud at gmail.com
Mon Jul 19 11:44:54 PDT 2010


On Mon, Jul 19, 2010 at 03:03, Robert Jacques <sandford at jhu.edu> wrote:


> A well designed opDollar is still an enhancement request:
> http://d.puremagic.com/issues/show_bug.cgi?id=3474.


Ah, OK.


> However, there is a hack to get $ to return a value. Unfortunately, I've
> lost that newsgroup post.
>
> 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 :)




> Memory got me this code snippet:
>
>
> struct Bar {
>    int opIndex(int i) { writeln(i); return i; }
>
> }
> int __dollar() { return 5;}
>
>
> void main(string[] args) {
>    Bar b;
>    b[$];
> }
>

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.

Oh well, I'll push slices away from now, and use drop. Too bad, that would
have make some parts more elegant.

Thanks Robert,


  Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100719/8eac5ff4/attachment.html>


More information about the Digitalmars-d mailing list