Mixin Template: cannot mixin scope(exit)?

Nicolas Sicard dransic at gmail.com
Tue Jan 15 02:32:26 PST 2013


On Monday, 14 January 2013 at 06:26:33 UTC, 1100110 wrote:
> On 01/13/2013 11:35 PM, 1100110 wrote:
>> Ok, I wish to create a standard timing system so that I can 
>> measure ~how
>> long each function takes to execute.
>>
>> I wish to be able to place at the start of a function
>> version(Time) mixin TimeExecution("funcName");
>>
>> mixin template TimeExecution(T) if(isSomeString!T) {
>> import std.stdio, std.datetime, std.conv;
>>
>> auto sw = StopWatch(AutoStart.yes);
>> // Error: Declaration expected, not '('
>> scope(exit) writeln(T, ": ", to!Duration(sw.peek));
>> }
>>
>>
>> Why do I receive the Error when the scope statement is 
>> included?
>> Is this an error, or what is the rationale behind the decision?
>>
>> Thank you.
>
> It appears that you cannot mixin *any* statement with 
> scope([exit,success,etc]) in it.

Mixin templates are supposed to introduce *declarations* not 
statements.

Eg. even this shouldn't compile, should it?
---
mixin template TimeExecution(T) if(isSomeString!T) {
     import std.stdio;
     writeln(T); // statement
}
---


More information about the Digitalmars-d-learn mailing list