Simple implementation of __FUNCTION
mist
none at none.none
Fri Nov 2 11:23:25 PDT 2012
Sweet! You may also find my pull request for phobos ( #863,
fullyQualifiedTypename ) useful for adding function signature
once it gets finalised and merged.
On Friday, 2 November 2012 at 17:31:55 UTC, Rob T wrote:
> Thanks to input from the D community, I've managed to implement
> a reasonable way to log the name of a calling function. This is
> used for basic execution monitoring and for automated logging
> of exception errors.
>
> Here's what I did.
>
> template __FUNCTION()
> {
> const char[] __FUNCTION = "__traits(identifier,
> __traits(parent, {}))";
> }
>
> Example use in code:
>
> throw new Exception( "Error: Function ", mixin(__FUNCTION!()) );
>
> writefln( "File: %s, Func: %s, Line: %d", __FILE__,
> mixin(__FUNCTION!()), __LINE__ );
>
>
> The ONLY thing left that I would like to have, is ability to
> display the function signature along with the name. The
> signature will be very useful to show which version of an
> overloaded or templated function was called.
>
> If anyone can suggest imporvements, like how to get rid of need
> to explicitly call mixin, and better yet a solution to get the
> function signature, please post away. Thanks!
>
> I have to mention that we need a real solution that can only be
> provided through improved reflection support, eg
> __scope.function, __scope.line, __scope.file, etc, or whatever
> the D community thinks will fit in best.
>
> --rt
More information about the Digitalmars-d
mailing list