Paralysis of analysis

Steven Schveighoffer schveiguy at yahoo.com
Tue Dec 14 12:08:02 PST 2010


On Tue, 14 Dec 2010 14:56:55 -0500, Kagamin <spam at here.lot> wrote:

> Andrei Alexandrescu Wrote:
>
>> That all being said, I'd like to make a motion that should simplify
>> everyone's life - if only for a bit. I'm thinking of making all
>> containers classes (either final classes or at a minimum classes with
>> only final methods). Currently containers are implemented as structs
>> that are engineered to have reference semantics. Some collections use
>> reference counting to keep track of the memory used.
>
> Thinking about this I've found an interesting issue:
>
> ---
> void foo(int[int] aa)
> {
> 	aa[2]=2;
> }
>
> int main()
> {
> 	int[int] aa;
> 	//aa[1]=1; //uncomment this and it will work
> 	foo(aa);
> 	assert(aa[2]==2);
> 	return 0;
> }
> ---

That's been discussed very much in the past.  There is no good solution,  
and it's one of the good reasons to make collections classes with clearly  
defined lifetimes.

I can't find the thread that talks about this, but I think it was over a  
year ago that I brought up this subtlety when people were wondering what  
the correct implementation for containers should be -- struct or class.

-Steve


More information about the Digitalmars-d mailing list