Decision on container design

Michel Fortin michel.fortin at michelf.com
Tue Feb 1 11:01:06 PST 2011


On 2011-02-01 12:07:55 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> With this, the question becomes a matter of choosing the right default: 
> do we want values most of the time and occasional references, or vice 
> versa? I think most of the time you need references, as witnessed by 
> the many '&'s out there in code working on STL containers.

What exactly is "most of the time"? In C++, you pass containers by '&' 
for function parameters, using '&' elsewhere is rare.

One thing I proposed some time ago to address this problem (and to 
which no one replied) was this:

	ref struct Container { ... } // new "ref struct" concept

	void func(Container c) {
		// c is implicitly a "ref Container"
	}

	Container a; // by value
	func(a); // implicitly passed by ref

Containers would be stored by value, but always passed by ref in 
functions parameters.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list