Trying to get current function name results in compiler error with __traits

Sepheus noreply at sepheus.co.uk
Fri Dec 7 11:55:29 UTC 2018


On Friday, 7 December 2018 at 02:37:34 UTC, Arun Chandrasekaran 
wrote:
> I'm trying to get the current function name and apparently the 
> commented line errors out.
>
> What am I doing wrong?
>
> https://run.dlang.io/is/EGsRU2
>
> ```
> #!/usr/bin/rdmd
>
> void main()
> {
>     import std.experimental.all;
>     void foo() {
>         // __traits(identifier, mixin(__FUNCTION__)).writeln; 
> // compilation error
>         __FUNCTION__.split('.')[$-1].writeln;
>     }
>     __traits(identifier, mixin(__FUNCTION__)).writeln;
>     __FUNCTION__.split('.')[$-1].writeln;
>     foo();
> }
> ```

Looks like this will do the trick https://run.dlang.io/is/cX3S37



More information about the Digitalmars-d-learn mailing list