Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
2.5.2
-
C++ generic
Description
I was browsing the mongodb code in doxygen (I'm thinking of "stealing" your ptr<T> class) and noticed that the operator->() and operator*() (dereference) are not const correct:
T* operator->() const
{ return _p; }T& operator*() const { return *_p; }
operator T* () const { return _p; }
should be:
const T* operator->() const
{ return _p; }const T& operator*() const { return *_p; }
operator const T* () const { return _p; }
// ... and if you want non-const versions.
T* operator->()
T& operator*() { return *_p; }
operator T* () { return _p; }
If there is some rationale for violating the const correctness, it should at least be documented in a comment (didn't notice anything in the doxygen documentation regarding this).