www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __FUNCTION__?

reply "js.mdnq" <js_adddot+mdng gmail.com> writes:
We have __FILE__ and __LINE__. Is there a __FUNCTION__ that gives 
the current function name? This helps with errors.
Feb 25 2013
next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Monday, 25 February 2013 at 16:32:50 UTC, js.mdnq wrote:
 We have __FILE__ and __LINE__. Is there a __FUNCTION__ that 
 gives the current function name? This helps with errors.
Have a look here: http://wiki.dlang.org/Using_string_mixins_for_logging
Feb 25 2013
prev sibling next sibling parent Nick Treleaven <ntrel-public yahoo.co.uk> writes:
On 25/02/2013 16:32, js.mdnq wrote:
 We have __FILE__ and __LINE__. Is there a __FUNCTION__ that gives the
 current function name? This helps with errors.
You can define a string mixin to use instead of __FUNCTION__: enum string parentName = q{__traits(identifier, __traits(parent, {}))}; void main() { writeln(mixin(parentName)); // prints "main" }
Feb 25 2013
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 2/25/13, js.mdnq <js_adddot+mdng gmail.com> wrote:
 We have __FILE__ and __LINE__. Is there a __FUNCTION__ that gives
 the current function name? This helps with errors.
We'll have it sometime soon. http://d.puremagic.com/issues/show_bug.cgi?id=5140 https://github.com/D-Programming-Language/dmd/pull/1462
Feb 25 2013
prev sibling parent "Rob T" <alanb ucora.com> writes:
On Monday, 25 February 2013 at 16:32:50 UTC, js.mdnq wrote:
 We have __FILE__ and __LINE__. Is there a __FUNCTION__ that 
 gives the current function name? This helps with errors.
As was previously stated there's a pending pull request that properly implements __FUNCTION__ and more. If you can't wait for it, this is what I've been using ... // put this in a module to re-use ... // support functions string fg_MakeFuncSig( string a_FName, string a_Sig ) { return a_FName ~ "<" ~ a_Sig ~ ">"; } string fg_MakeObjFuncSig( string a_OName, string a_FName, string a_Sig ) { return a_OName ~ "." ~ a_FName ~ "<" ~ a_Sig ~ ">"; } // function name only enum __FUNCTION_NAME = q{ __traits(identifier, __traits(parent, {})) }; // function name and signature enum __FUNCTION_SIG = q{ fg_MakeFuncSig( __traits(identifier, __traits(parent, {})), typeof(__traits(parent, {})).stringof ) }; // class or struct member function name and signature enum __OBJ_FUNCTION_SIG = q{ fg_MakeObjFuncSig( typeof(this).stringof, __traits(identifier, __traits(parent, {})), typeof(__traits(parent, {})).stringof ) }; // example code showing use. struct X { void test( int a_i ) { writeln( mixin(__OBJ_FUNCTION_SIG) ); } } int main() { writeln( mixin(__FUNCTION) ); writeln( mixin(__FUNCTION_SIG) ); X x; x.test(1); } --rt
Feb 26 2013