opDollar and infinite slices on infinite ranges
Philippe Sigaud
philippe.sigaud at gmail.com
Thu Jul 22 10:59:26 PDT 2010
On Wed, Jul 21, 2010 at 21:47, Simen kjaeraas <simen.kjaras at gmail.com>wrote:
>
> I wrote this indexing struct. Clearly not perfect, but it sorta does the
> right things:
>
> To use, make opSlice take an Index parameter, and call its opCall with the
> length
> of the container.
OK, it take the length and compute the result index, as in $/2+5, etc.
OK, I defined an opSlice(size_t i1, Index i2) {...} and it worked! Thanks
Simen !
In my case, I guess the Index is just there to be a sentinel value,
generated by __opdollar, as I for an infinite range, I do not have a length
to give it, I just want arithmetic operations on Index to always return an
Index.
Except... I cannot do that: c[2..$+$] ... Ah, I get it: maybe like this:
Index opBinary( string op )( Index i ) const {
Index result;
result.dg = ( long value ) {
mixin( "return dg( value ) " ~ op ~ " i(value);" );
};
return result;
}
I don't understand you opUnary code:
Index opUnary( string op )( ) {
dg = ( long value ) {
mixin( " auto tmp = dg( value ); tmp" ~ op ~ "; return tmp;" );
};
return this;
}
Shouldn't that be ;" ~ op ~ "tmp; return tmp;" ?
So, cool, that works. I'll just have to check if operations on 'infinite'
Index work as they should.
> Wish there was a way to make late-bound templates in D, as that
> could allow for different value types depending on usage.
> Hm, maybe there is a way, now that I think of it. I shall have to check in
> the future.
>
>
What do you mean?
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100722/02e9a7dc/attachment.html>
More information about the Digitalmars-d
mailing list