passing __FILE__, __MODULE__, etc... with varadic types

JS js.mdnq at gmail.com
Fri Jul 19 10:23:50 PDT 2013


On Friday, 19 July 2013 at 15:32:25 UTC, Jonathan M Davis wrote:
> On Friday, July 19, 2013 11:06:26 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?
>
> As long as you're using a templated function and thus can use 
> IFTI (implicit
> function template instantation) instead of giving the template 
> arguments
> explicitly, you don't have to put the template parameters with 
> default
> arguments last. You'd just have to put it after the variadic 
> parameter if you
> intended to give the template arguments explicitly. So, as long 
> as you don't
> have to give the template arguments explicitly, you're fine. If 
> you need to
> give them explicitly though, I think that you're stuck.
>
> - Jonathan M Davis

I don't at all see how this could possibly work. The order of 
parameters is crucial. With a type tuple it may be different but 
I just tried and it didn't work:

template A(string f = __FILE__, T...)
{
	pragma(msg, f);
	enum A = T.stringof;
}

called with A!(int, double) and got an error about argument type 
mismatch.

So unless you are talking about something else or there is some 
"trick" involved I don't think this works...


More information about the Digitalmars-d-learn mailing list