caller trouble

captaindet 2krnk at gmx.net
Sat Jul 14 11:30:03 PDT 2012


On 2012-07-14 02:12, Jonathan M Davis wrote:
[..]
> I believe that __FILE__ and __LINE__ are treated specially with
> functions in order for them to be filled in at the call site rather
> than the declaration site. If it's not working with classes, then
> that probably means that whatever special logic was done to make them
> work with functions was only done for functions.

IIRC, __FILE__ is a template itself. so it must be about the very moment it is resolved. apparently, for function (templates) default parameters are treated as if given on the caller side. maybe even for __FILE__ and __LINE__ as main usage case? in any case, there would be a consistent rule "resolve all templates in argument lists on caller side, including default parameters" if it were not broken for class templates. moreover, i am puzzled why the small variation in usage rusults in an inconsistent outcome:

auto _tclass = new tclass!();             //_tclass.from == "other.d" !!!
auto _tclassx = new tclass!(__FILE__)();  //_tclass.from == "main.d"


> However, I would point out that that would mean that every single
> module which uses tclass would end up with a different and
> incompatible instantiations of tclass

yes, but not an issue in my case. there would be only one object, created from the main module. background: i want to do some compile time magic including parsing information from a file that always has the same name as the module containing main(){...}.


> However, if you _really_ want something like this, you can always
> just wrap the creation of the object in a function:

good idea, i will try this next.

thanks for your help!

/det


More information about the Digitalmars-d-learn mailing list