I already know that you can enable (or not) a class method using std::enable_if
for example:
template<size_t D, size_t E> class Field { ... size_t offset(const std::array<float,D>& p) const { ... } template<typename TT = size_t> typename std::enable_if<D!=E, TT>::type offset(const std::array<float,E>& p) const { return offset(_projection(p)); } ... };
This helps not to call a function that is not valid in a particular case, and also eliminates overload errors ... which is very nice for me!
I would like to go further and make some of my class members present only if they are needed. Thus, I get an error if I try to use an object that would not otherwise be triggered.
I tried to do
template<size_t D, size_t E> class Field { ... template<typename TT = projectionFunc> typename std::enable_if<D!=E, TT>::type _projection; }
But the compiler tells me:
erreur: data member '_projection' cannot be a member template
Is there any way to achieve what I want?
source share