Can this solution be turned into a macro so that I call something along the lines of:
CALL_CONST_FUNC(objToReturn, thisPtr)->SomeConstFunc();
For functions that return a value and another for functions that don’t. My macro token skills are not that great so I thought maybe someone here can come up with one (or tell me that it is not possible). Ultimately the goal is to avoid writing the ugly one-liner and replace it with something that is easy on the eyes and not error prone.
If a function doesn’t return a value (reference or pointer), do you need const overloads in the first place? It seems that the only reason to have two is to get a const or non-const reference out of the class. Otherwise the const version alone should be enough.
As to making the idiom sweeter, how about a few template helpers instead to do type deduction for you:
The benefit is greater if the type names are longer.