jeudi 1 décembre 2016

C++ templates, use of enable_if for two different implementation of an operator

I have, at some point in my code, an overload like this

template<int L>
template<int M>
inline StaticMemory<L>& StaticMemory<L>::operator =(const StaticMemory<M>& _m)
{
   if (this != &_m) { //Problem here!
      set_ui(this->mem, _m.mem, L, M);
   }
   return *this;
}

What happens is that the check I highlighted is basically wrong, because when L != M the pointer comparison is notvalid, unless I cast it. I could cast the pointer probably, but is there a way to use the std::enable_if to maybe write two different versions of such operator?

Thx

Aucun commentaire:

Enregistrer un commentaire