New __FILE_DIR__ trait?

Sebastien Alaiwan via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 28 10:21:52 PDT 2016


On Thursday, 28 July 2016 at 06:21:06 UTC, Jonathan Marler wrote:
> auto __DIR__(string fileFullPath = __FILE_FULL_PATH__) pure
> {
>     return fileFullPath.dirName;
> }

Doesn't work, I don't think you can wrap such things ( __FILE__ 
and such ):

import std.stdio;

int main()
{
   printNormal();
   printWrapped();
   return 0;
}

void printNormal(int line = __LINE__)
{
   writefln("%s", line);
}

void printWrapped(int line = __MY_LINE__)
{
   writefln("%s", line);
}

// wrapped version
int __MY_LINE__(int line = __LINE__)
{
   return line;
}

$ rdmd demo.d
5
15  (should be 6!)

Thus, the suggested implementation of __DIR__ would behave very 
differently from a builtin one. I'm not saying we need a builtin 
one, however, it might not be a good idea to name it this way.




More information about the Digitalmars-d mailing list