passing __FILE__, __MODULE__, etc... with varadic types
JS
js.mdnq at gmail.com
Fri Jul 19 03:54:25 PDT 2013
On Friday, 19 July 2013 at 09:06:27 UTC, JS wrote:
> I would like to pass to all my templates the file and module
> locations where they are used(this goes into a debugging system
> I have come up with).
>
> The problem is, with varadic types being passed I can't do this:
>
> template T(T..., string file = __FILE__)
>
> doesn't work.
>
> I think there is no way around except to explicitly pass
> __FILE__... which would be a mess?
I should mention, that because file is at the end of the
parameter list and it will never be supplied by the user, there
should be no reason it should fail...
I think d should allow such a feature as it is more useful and
necessary in some cases...
e.g.,
template A(T..., hidden string file = __FILE__, hidden string mod
= __MODULE__)
only hidden parameters with default values can be used after a
template type tuple.
if I try to use a mixin in some way, dmd crashes:
import std.stdio, std.cstream;
template TT(T...)
{
enum TT = "T(__FILE__, __MODULE__)";
}
template T(string file, string mod, T...)
{
enum T = file~"\n"~mod;
}
void main(string[] argv)
{
writeln(mixin(TT!()));
din.getc();
}
More information about the Digitalmars-d-learn
mailing list