opSlice and $
Witold Baryluk
baryluk at smp.if.uj.edu.pl
Tue Sep 11 16:43:41 PDT 2007
Dnia Tue, 11 Sep 2007 18:08:12 -0400
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> napisał/a:
> "Robert Fraser" <fraserofthenight at gmail.com> wrote in message
> news:fc70uu$o8r$1 at digitalmars.com...
> > Sean Kelly Wrote:
> >>
> >> I would love this. It would be quite useful for ordered
> >> associative sequences (red-black tree, etc).
> >
> > Got my vote!
> >
>
> ...?
>
[cut]
Thanks. I have read D specification too literally :)
Indeed this works:
import std.stdio;
class A {
char[] opSlice(char[] x, char[] y) {
return x ~ y;
}
char[] opSlice(char[] x, int y) {
char[] z = "";
for (int i = 0; i < y; i++) {
z ~= x;
}
return z;
}
}
void main() {
auto a = new A();
auto b = a["a" .. "z"];
writefln(b); // prints az
auto c = a["a" .. 7];
writefln(c); // prints aaaaaaaa
}
--
Witold Baryluk, aleph0
MAIL: baryluk at smp.if.uj.edu.pl
JID: movax at jabber.autocom.pl
More information about the Digitalmars-d
mailing list