"Robert Jacques" <[email protected]> wrote in message
news:[email protected]...
>
> I would favor some form of AST as opposed to raw strings,
Definitely, but strings would probably a lot easier to put in and work well
enough in the meantime.
I just came across another case where access to original source would be
useful. I have a helper tool in my SemiTwistDTools lib that I use all the
time that works like this:
int a=3;
mixin(traceVal!("a+4"));
// runtime output:
a+4: 7
Which is almost as much a pain to type as it is useful. But if there was a
finer-graned version of __traits(getSource, function), say, to get the
source of a parameter from the caller's side, then I could probably just
simplify it to this:
traceVal(a+4);
By doing something like this:
void traceVal(T, string str = __traits(getParamSource, expr))(T expr)
{
writeln(str, ": ", expr);
}
Which would be similar to this trick already in D2:
int bar(int line = __LINE__)()
{
return line;
}
void main()
{
#line 1000
writeln(bar()); // Output: 1000
}
...Although in testing that I just noticed that defining bar this way
doesn't work the same:
template bar(int line = __LINE__)
{
enum bar = to!string(line);
}
Bug?