opDollar and infinite slices on infinite ranges
Don
nospam at nospam.com
Mon Jul 19 11:58:45 PDT 2010
Philippe Sigaud wrote:
> On Mon, Jul 19, 2010 at 03:03, Robert Jacques <sandford at jhu.edu
> <mailto: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 :)
It's still planned to be implemented. The patch I made didn't have
enough description for Walter to be comfortable with including it yet.
>
>
>
>
> 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
>
>
>
More information about the Digitalmars-d
mailing list