Is there a way to compare the result decltypein C ++ 11?
In other words, why is this code invalid:
template<typename T, typename U>
void func(T& t, U& u) {
if(decltype(t) == decltype(u)) {
} else {
}
}
I know that in some cases this particular problem can be solved by partial specialized specialization; my question is about comparing decltypes.
Change: . The question arose when trying to provide default values for free features through SFINAE. Perhaps the best question is why this is not true:
template<bool B>
bool SomeFunction() { ... }
template<typename T, typename U>
bool SomeFunctionWrapper(T& t, U& u) {
SomeFunction<decltype(t) == decltype(u)>();
}
Since then, I have found another solution (which does not include templates at all), but at one point I tried this:
typedef struct { char } undefined;
template<typename T = void>
undefined AFreeFunction();
template<bool B>
bool AFreeFunctionWrapper_() {
return false;
}
template<>
bool AFreeFunctionWrapper_<false>() {
return AFreeFunction();
}
bool AFreeFunctionWrapper() {
return AFreeFunctionWrapper_<decltype(AFreeFunction()) == decltype(undefined)>();
}
, GCC 4.6, , MSVC, 2012 RC. , :
class AFreeFunction {
public:
operator bool() { return false; }
};
, . , , bool.