jeudi 3 septembre 2020

Define C++ conversion operator only if template arg is not const

I'm writing custom conversion operator from CContainer<CLASS> to CContainer<const CLASS>. The code looks like this:

template<class T>
class CContainer
{
public:
    operator CContainer<const T>() const { /* here goes the code */ }
};

and technicaly it works well, but some compilers print warnings like operator CContainer<const T>() const will never be used each time when there is an explicit instantiation with constant template argument, like CContainer<const float> constFloatContainer;.

Is there a way to avoid this warning, and define operators like this only when T is not const in C++11?

Aucun commentaire:

Enregistrer un commentaire