Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2002-06-23 10:52:25


I've been using the Pimpl idiom on the last semester using a
boost::shared_ptr<> to
hold the pimpl. A thing that irritated me was that constness of a routine
did not
propagate to the pimpl because boost::shared_ptr's operator->() returns a

template<typename T> class shared_ptr {
T * operator->() const; // never throws

This will allow this code to compile although (IMO) it is not supposed to:

struct Int
    int i;
    void foo() { i++; }

class C
    boost::shared_ptr<Int> p_;
    C() : p_( new Int ) { }
    void can_modify() { p_->foo(); }
    void can_also() const { p_->foo(); } // breaks constness contract

Am I right that this is undesired behavior? If so, this extension to
the smart pointers should be done:

template<typename T> class shared_ptr {
const T * operator->() const; // disallows a call to non-const functions
return value
T* operator->();

and also for operator*().



Boost list run by bdawes at, gregod at, cpdaniel at, john at