As you have noticed, your problem comes from the fact that you're adding a top-level const
to your template parameter, but when it comes to pointers it yields T * const
not T const *
.
Specializing your template is one way to do achieve what you want.
Another way would be to make a helper template that takes care of the deep "constification" and use this in your main template. This is usually easier to do it that way because it means less code duplication. Something along the lines of:
template<typename C>
struct Constify {
typedef const C type;
};
template<typename C>
struct Constify<C*> {
typedef const C* const type;
};
template<class C>
class Array
{
inline int Search(typename Constify<C>::type & value) const;
...
};