Error Message useless

Simen Kjaeraas simen.kjaras at gmail.com
Sun May 11 19:07:18 PDT 2008


On Sun, 11 May 2008 02:04:00 +0200, janderson <askme at me.com> wrote:

> janderson wrote:
>>  Here's a tip:
>>  Use: __FILE__, __LINE__ in your arguments.  That way you don't need to  
>> keep changing the value.
>>  I bet one could write a mixin that would do this automatically and  
>> you'd simply wrap each function in that mixin.
>>  -Joel
>
> On further thought that might not work.  I'm not sure what would be in  
> __FILE__ and __LINE__.  However the mixin could still print out the  
> actual code that was just before the ";".
>
> -Joel

import std.stdio;
import std.traits;

template _debug(alias f, int line = __LINE__, string file = __FILE__)
{
	ReturnType!(f) _debug(ParameterTypeTuple!(f) u)
	{
		writefln("%s(%d) executed.", file, line);
		return f(u);
	}
}


Usage:

_debug(function)(parameters);


There might be a simpler, more prettiful way to find the return type and  
parameters, but this works.

-- Simen



More information about the Digitalmars-d mailing list