I mean to have a templated function that depends on a size_t
template parameter.
I have a "fallback" definition, placed in my sfinae.h
.
template <size_t dim>
int sumVec(void) {
return -1;
}
I already have a couple of specializations for specific values of dim
, e.g. in my sfinae.cc
,
template <>
int sumVec<2>(void) {
return 2;
};
and its prototype in sfinae.h
.
Now I want to define one specialization that applies for several values of dim
, so I mean to avoid having to replicate it several times.
I could make dim
into an enum class
, as done in One template specialization for several enum values
My question is Can I achieve my objective without (heavily) changing the code I have (but I could add to it)?
I tried adding code below either in the header or the source, and the compiler (gcc 10.2.0) threw an error non-class, non-variable partial specialization 'sumVec<std::enable_if<((dim == 3) || (dim == 4)), void> >' is not allowed
so I am not sure I am not using the right approach or syntax, or what I asked is not allowed by the compiler.
template<size_t dim>
int sumVec<std::enable_if<dim == 3 || dim == 4>>(void)
{
return dim;
};