M
Marc
Hello,
I have code like:
template<class A,class B> struct Demo {
// here a large body of code
void f(A);
void f(B);
};
If A and B are the same type, this won't work. To remove the second
overload when A==B, you may think of replacing void with
enable_if<!is_same<A,B>::value,void>::type, but that won't work because
A and B are not dependent names. You can artificially make them
dependent, but that doesn't seem right. You can make the second overload
take a type that is B if A!=B and a dummy type otherwise, but that can
cause problems too. You can have 2 specializations of the class, but you
duplicate plenty of code.
How do you usually handle this sort of thing?
I have code like:
template<class A,class B> struct Demo {
// here a large body of code
void f(A);
void f(B);
};
If A and B are the same type, this won't work. To remove the second
overload when A==B, you may think of replacing void with
enable_if<!is_same<A,B>::value,void>::type, but that won't work because
A and B are not dependent names. You can artificially make them
dependent, but that doesn't seem right. You can make the second overload
take a type that is B if A!=B and a dummy type otherwise, but that can
cause problems too. You can have 2 specializations of the class, but you
duplicate plenty of code.
How do you usually handle this sort of thing?