digitalmars.D.learn - __FUNCTION__?
- js.mdnq (2/2) Feb 25 2013 We have __FILE__ and __LINE__. Is there a __FUNCTION__ that gives
- Vladimir Panteleev (3/5) Feb 25 2013 Have a look here:
- Nick Treleaven (7/9) Feb 25 2013 You can define a string mixin to use instead of __FUNCTION__:
- Andrej Mitrovic (4/6) Feb 25 2013 We'll have it sometime soon.
- Rob T (41/43) Feb 26 2013 As was previously stated there's a pending pull request that
We have __FILE__ and __LINE__. Is there a __FUNCTION__ that gives the current function name? This helps with errors.
Feb 25 2013
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
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
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
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