I have a template function called "inspect" that takes two variables as arguments,

void inspect(T)( string symbol, T value )
{
   writeln(symbol, " = ", value);
}

int y = 100;

inspect( y.stringof, y );

writes to console

y = 100

I am wondering if there's a way to pass only the variable and have the inspect function determine the variable's symbol name as passed rather than have to pass both the name and value separately?

void inspect(T)( T value )
{
   writeln( ? , " = ", value);
}


I've tried a template with alias parameter

void inspect(alias value)()
{
   writeln( value.stringof , " = ", value);
}

It works except when passing a variable contained inside a struct or class due to a missing "this" during evaluation, I'm also worried about template bloat.

I figure mixins may help, but not if it's same or less convenient to use as the double entry method.

Any suggestions, or is it just impossible or not worth trying?

--rt

Reply via email to