[OT] Finding longest documents

Steven Schveighoffer schveiguy at yahoo.com
Wed Oct 15 11:45:09 PDT 2008


"Sergey Gromov" wrote
> Wed, 15 Oct 2008 09:49:08 -0500,
> Andrei Alexandrescu wrote:
>> Sergey Gromov wrote:
>> > Wed, 15 Oct 2008 09:17:57 -0500,
>> > Andrei Alexandrescu wrote:
>> >> I see how it breaks those conventions, but I've never heard of them. 
>> >> The
>> >> convention I heard of is that if you want dynamic polymorphism you use
>> >> classes, otherwise you don't.
>> >
>> > How about if you want pass-by-value you use structs, otherwise you 
>> > don't?
>> > My argument against structs-collections is that I want to toss
>> > collections around and build other collections out of them without
>> > messing with pointers.
>>
>> A struct can choose to implement value or reference semantics as it
>> pleases. The only thing it can't readily implement is dynamic 
>> polymorphism.
>
> I can imagine the documentation: "Ignore the fact it's a struct, it's
> actually a reference internally."  So how do I return it?  Should I
> return it by value, hoping that the implied reference semantics will stay
> that way in future releases?  How does your Array!() behave?

There's nothing requiring that a struct must implement value semantics.  The 
fact that you are expecting such just because it is a struct is a mistake.

The reality is that only structs can implement value semantics because of 
the inability to override A = A in a class.

That being said, I think containers work best as a mixture of interface and 
compile-time typing. See http://www.dsource.org/projects/dcollections.

-Steve 





More information about the Digitalmars-d mailing list