template ptr<T> class not const correct

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.5.2
    • Component/s: Internal Code
    • Environment:
      C++ generic
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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->()

      { return _p; }
      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).

            Assignee:
            Andy Schwerin
            Reporter:
            Michael H. Cox
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: