More D newb questions.

Walter Bright newshound1 at digitalmars.com
Tue May 6 10:27:28 PDT 2008


Me Here wrote:
>> Secondly, what about
>> structs? Should structs behave like basic types, or like arrays here? (I
>> discussed this conundrum further in another post in this thread.)
> 
> If the struct has a opCat method with match type signature, dispatch to it.
> If not, raise an error.

One of the principles of D is that a struct can be used to 'wrap' any 
type, and be able to behave like that type. So for your proposal:

struct S { char c; }
S s;
char c;
c ~ c => char[]
s ~ s => error!


> Hmm. How do you balance that view with the impact of
> immutable strings in Dv2?

I don't agree that immutable strings are slower, but even so, you don't 
have to use immutable strings in D. char[] can be used. There's no way 
to avoid the extra tests if overlapping copies are allowed.

> Eg. (something like) struct slice { T[]* parent; type_t pos; type_t length }

It's { length, ptr }.



More information about the Digitalmars-d mailing list