dcollections 1.0 and 2.0a beta released

Michel Fortin michel.fortin at michelf.com
Sat May 22 05:17:12 PDT 2010


On 2010-05-22 07:56:31 -0400, Michel Fortin <michel.fortin at michelf.com> said:

> 	@explicitdup struct Array {  }
> 
> 	void testVal(Array array);
> 	void testRef(ref Array array);
> 
> 	unittest {
> 		Array array;
> 		testVal(array);     // error, cannot copy array implicitly
> 		testVal(array.dup); // ok, array is copied
> 		testRef(array);     // ok, array is passed by reference
> 	}
> 
> If there's already a way to achieve this, I couldn't find it.

Apparently it's already achievable this way:

	struct Array {
		@disable this(this);
		Array dup() { return Array(...); }
		...
	}

It also blocks simple assignments:

	Array array2 = array;     // error, array is not copyable
	Array array3 = array.dup; // ok

With this, I don't think we need containers to be reference types 
anymore. The naive error of copying containers everywhere without you 
knowing about it (as it occurs in C++) is simply no longer possible.

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



More information about the Digitalmars-d-announce mailing list