You cannot use enable_if
to enable / disable member functions based on class template parameters: enable_if
can only be applied to function or class templates.
In your case, the only solution I can think of is specializing in the whole class using enable_if
or more simply with partial specialization. You can put common members in a common base class so you don't have to repeat them:
#include <cstdio> template<typename T, std::size_t N> struct VectorCommon { std::size_t size() { return N; } void add(T const & element) { } }; template <typename T, std::size_t N> struct Vector : VectorCommon<T, N> { }; template <typename T> struct Vector<T, 2> : VectorCommon<T, 2> { Vector(T const & e0, T const & e1) {} }; int main() { //Vector<int, 100> v100(12, 42); // compile error Vector<char, 2> v2('a', 'b'); // ok }
source share