A new class -->String
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Thu Apr 5 13:08:19 PDT 2007
Dan wrote:
>
> I totally disagree with Class'ing a simple data type just to introduce
> functions to handle it.
I'm sure we all agree on that. Extending previously closed classes is a
valuable feature in modern object oriented programming.
>
> Especially since you can use that pretty OO notation on arrays simply by
> having the functions accept the array as the first argument. This works:
>
> void slice(inout char[] s, size_t start, size_t finish){
> ...
> }
>
> char[] myS = "Hello! How are you?";
>
> myS.slice(2,6);
That is what I pointed out previously. But the current syntax is limited to
a few special cases. You cannot do something like
auto myS = "moo";
char[] opMul(char[] str, int count) {
char[] tmp;
for(int i=0; i<count; i++) tmp ~= str;
return tmp;
}
auto s2 = myS * 3; // = "moomoomoo"
Also you cannot specify constraints on the use of these implicit
conversions. I have not enough expertise on this, but it is good to know
that some other languages have found working solutions.
More information about the Digitalmars-d
mailing list