Mixin Template: cannot mixin scope(exit)?

Timon Gehr timon.gehr at gmx.ch
Mon Jan 14 00:03:35 PST 2013


On 01/14/2013 07:26 AM, 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.
>
> I have been rereading my copy of TDPL, and it states that mixin
> statements must be valid D code, and there can be multiple 'scope()'
> statements.
>
> Since "scope(exit) writeln();" is valid D code, and refuses to compile
> in a mixin, I assume that this is a bug.
>
> I've been digging through the bug tracker and I cannot find a duplicate
> bug, so if someone can confirm that this is a bug, I'll create a report.

It is not a bug. Use a string mixin.


More information about the Digitalmars-d-learn mailing list