digitalmars.D.learn - Getting function argument names?
- Sean Cavanaugh (16/16) Apr 20 2011 I am working on a template class to provide function wrappers for COM
- Jacob Carlborg (5/21) Apr 20 2011 Not perfect (i.e. can't handle delegates) but works good enough:
I am working on a template class to provide function wrappers for COM based objects, so the calling code doesn't have to dereference the underlying pointer. In C++ we get this behavior for 'free' by overloading operator->. In D I can create a fairly funky mixin template to inspect the contained class and auto-generate a bunch of wrapper functions. Its easy enough to get the function list, by looping on __traits(getVirtualFunctions) for a class type, and feeding the results into MemberFunctionsTuple!(). This needs to be followed up by repeating the process for each base class specified , via BaseClassesTuple!(). So the real question: Is there any way to get to the friendly names for function arguments discovered through the traits system? MemberFunctionsTuple!() only returns the types as far as i can tell, which technically is enough for me to automatically name them something boring ArgA ArgB ArgC procedurally, is not a very nice thing to look at.
Apr 20 2011
On 2011-04-20 22:05, Sean Cavanaugh wrote:I am working on a template class to provide function wrappers for COM based objects, so the calling code doesn't have to dereference the underlying pointer. In C++ we get this behavior for 'free' by overloading operator->. In D I can create a fairly funky mixin template to inspect the contained class and auto-generate a bunch of wrapper functions. Its easy enough to get the function list, by looping on __traits(getVirtualFunctions) for a class type, and feeding the results into MemberFunctionsTuple!(). This needs to be followed up by repeating the process for each base class specified , via BaseClassesTuple!(). So the real question: Is there any way to get to the friendly names for function arguments discovered through the traits system? MemberFunctionsTuple!() only returns the types as far as i can tell, which technically is enough for me to automatically name them something boring ArgA ArgB ArgC procedurally, is not a very nice thing to look at.Not perfect (i.e. can't handle delegates) but works good enough: http://dsource.org/projects/orange/browser/orange/util/Reflection.d#L29 -- /Jacob Carlborg
Apr 20 2011