On 07/14/2012 08:53 AM, captaindet wrote:
i need a discreet handle on the calling/instantiating source file
(module). using __FILE__, it is surprisingly easy for functions (via
argument) and templated functions (via template parameter) but i cannot
get it working for templated classes. how can i make them aware of the
calling module?

thx, det


module other;

string fun(string infile = __FILE__){ return infile; }
string tfun(string infile = __FILE__)(){ return infile; }
class tclass(string infile = __FILE__){ string from = infile; }

//...//

module main;
import other;

void main(){
     auto _fun = fun();            //_fun == "main.d"
     auto _tfun = tfun();        //_tfun == "main.d"
     auto _tclass = new tclass!();    //_tclass.from == "other.d" !!!

     //this works but i do not want to provide __FILE__ explicitly:
     auto _tclassx = new tclass!(__FILE__)();    //_tclass.from == "main.d"
     //and why do i get 2 different results for the last 2 cases?
}

This is a bug.

dlang.org agrees: http://dlang.org/template.html#TemplateValueParameter

Reply via email to