An important potential change to the language: transitory ref

Michel Fortin michel.fortin at michelf.com
Sat Mar 20 06:10:54 PDT 2010


On 2010-03-20 07:53:34 -0400, Michel Fortin <michel.fortin at michelf.com> said:

> 	struct WrapperRange(R) {
> 		R wrappedRange;
> 		void applyFront(void delegate(ref ElementType!R) actor) {
> 			actor(wrappedRange.front);
> 		}
> 	}
> 
> 	R range;
> 	// Instead of this:
> 	range.front.callSomeFunc();
> 	// Use this:
> 	range.applyFront!((ref ElementType!R e) { e.callSomeFunc(); })();

Hum, this last line doesn't work, I should have written this:

	range.applyFront((ref ElementType!R e) { e.callSomeFunc(); });

No template. It could be done with a template, but then it couldn't 
work for virtual functions.

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




More information about the Digitalmars-d mailing list