I do not think that this can not be improved especially, which is sad, since I would like to find a way to do this.
Template type inference is only possible for function template arguments, and you need to pass a non-type function pointer at compile time so that it can be considered as a name, not a variable number. This means that all arguments must be specified.
i.e. You can do it:
template <class SomeLhs, class SomeRhs> void Add(ResultType (SomeLhs::*callback)(SomeRhs&)) { ... }
But then you have an actual pointer, which subsequently cannot be used as a template parameter.
The only thing I think you can do is use a macro, although it can be argued that it really improves the syntax here. I would say that this probably adds an unnecessary level of obfuscation.
eg.
#define TMFN_ARGS(C, M, P1) C, P1, &C::M tracker.Add<TMFN_ARGS(Quad, track, Multi)>();
EDIT:
However, if the function name is Always 'track', you can do something in the following lines:
template <typename C, typename P1> void AddTrack() { Add<C, P1, &C::track>(); } tracker.AddTrack<Quad, Multi>();
Pete
source share