Template accepting code blocks as a parameter.

David Medlock noone at nowhere.com
Wed Mar 1 07:16:37 PST 2006


Andrew Fedoniouk wrote:
> Let's say I'll be able to define mixin template which
> is able to accept block of code (aka closure) as a parameter.
> 
> So if I declare something like this:
> 
> template on_scope_exit(B: void delegate() )
> {
>     auto ScopeGuard sc#__LINE__ = new ScopeGuard(B);
> }
> 
> then I would like to be able to write something like this
> 
> mixin on_scope_exit! {  delete foo;  }
> 
> Which will expand to something like this at the point of mixin:
> 
> auto ScopeGuard sc1234 = new ScopeGuard( { delete foo; } );
> 
> This is just a rough idea.
> 
> Having this will allow to define onScope*** in the way that task needs
> and I beleive it will be useful in other places too.
> 
> Andrew
> http://terrainformatica.com
> 
> 
I suggested this some time ago:

http://www.digitalmars.com/d/archives/digitalmars/D/24770.html

If implemented it would allow foreach() to be implemented as a template.

-DavidM



More information about the Digitalmars-d mailing list