I figured out a better solution for this problem by combining the answers and comments here.
I can define a static type checker like so:
template <class A, class B>
struct CheckTypes
{
static const bool value = false;
};
template <class A>
struct CheckTypes<A, A>
{
static const bool value = true;
};
Not sure if such a struct already exists in the standard library. Anyways, then in Foo, I can check for types and sizes using:
static_assert((sizeof(T) == sizeof(long) || sizeof(T) == sizeof(int)) && !CheckTypes<T, float>::value, "Error!");