Skip to content

Instantly share code, notes, and snippets.

@iboB
Created April 22, 2012 06:03
Show Gist options
  • Save iboB/2459893 to your computer and use it in GitHub Desktop.
Save iboB/2459893 to your computer and use it in GitHub Desktop.
A way of checking if a class is derived from a template
template <typename A, typename B>
class myclass
{};
template <typename T>
struct is_myclass
{
struct yes { char c; };
struct no { char c[2]; };
template <typename A, typename B>
static yes check(myclass<A, B>*);
static no check(...);
static const bool value = sizeof(check(static_cast<T*>(nullptr))) == sizeof(yes);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment