c++ - Detect whether template parameter is cv-qualified -


i have existing code uses 'array' class represent 1d array. base template class implemented as

// forward declaration template<typename t> class array;  // implementation of 'const' array class: template<typename t> class array<const t> {   // ... }; 

this class has read-only interface, example element access operator present in const version:

const t& operator[](unsigned int i) const 

then there's class derived array, allows modification of member data:

template<typename t> class array<t> : public array<const t> 

the derived class supplies

t& operator[](unsigned int i) 

etc. in addition methods inherited parent. task perform refactoring of code extend functionality of array. while thinking options, know if there's way of detecting cv-qualifier of array's template parameter, example have

template <typename t> class array<t> {   public:      enum { is_const = template_param_is_const<t>::value; }      // ... }; 

and is_const have different values array<t> , array<const t>.

suggestions improvements of existing implementation preserve distinction between array<t> , array<const t> , above described behavior welcome.


Comments