More D newb questions.
Steven Schveighoffer
schveiguy at yahoo.com
Tue May 6 10:49:31 PDT 2008
"Walter Bright" wrote
> 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!
struct S { char c; S[] opCat(S s) {return [*this, s];} }
c ~ c => char[]
s ~ s => S[]
What is the problem with that?
-Steve
More information about the Digitalmars-d
mailing list