I would like to check if a certain template specialization exist or not, where the general case is not defined.
Given:
template <typename T> struct A; // general definition not defined
template <> struct A<int> {}; // specialization defined for int
I would like to define a struct like this:
template <typename T>
struct IsDefined
{
static const bool value = ???; // true if A<T> exist, false if it does not
};
Is there a way to do that (ideally without C++11)?
Thanks
Using the fact that you can't apply
sizeof
to an incomplete type:See it live on Coliru
Here is a slightly clunky, but working C++03 solution:
See it live on Coliru
This is an alternative implementation always using the same trick @Quentin used
C++11 version
Example on wandbox
Tentative C++03 version which does not work
The error in this case is