I've got a function
foo(int, int, int, int/long long/_int64/double/long double/char *, int ONLY IF previous char * - otherwise unneeded)
Problem is, char * implementation is different than the value types due to requiring a string copy. Yes, this is an interface to old code, so i cannot use std::string :/
Currently, I've got it as a template, and a function overload for char *, with the extra argument. However, all operations for the other types are also valid on char *, so if the caller forgets the last argument, the function silently matches the template instead, producing the wrong logic.
Is there any way I can force the usage of the overload/use default arguments in function templates/something that will allow for a different signature (extra argument) for a specific type without silently matching a lesser signature?
More: No access to C++11 yet, but I'm open to see a suggestion using it to help push for adoption. No boost, but same as above
I have also tried
return_type foo(int,int,int,typename std::enable_if<!std::is_pointer<T>::value, T>::type & value2update)
without any luck. It then claims that the call with a double & parameter fails to match.
int
is a length? Could you take a StringPiece instead to avoid the need for special-casing entirely? – Scott Lamb