Naming a typedef for a boost::shared_ptr<const Foo>

Posted by Blair Zajac on Stack Overflow See other posts from Stack Overflow or by Blair Zajac
Published on 2010-05-17T18:06:01Z Indexed on 2010/05/17 18:10 UTC
Read the original article Hit count: 348

Filed under:
|
|

Silly question, but say you have class Foo:

class Foo
{
public:
    typedef boost::shared_ptr<Foo> RcPtr;

    void non_const_method() {}
    void const_method() const {}
};

Having a const Foo::RcPtr doesn't prevent non-const methods from being invoked on the class, the following will compile:

#include <boost/shared_ptr.hpp>

int main()
{
    const Foo::RcPtr const_foo_ptr(new Foo);
    const_foo_ptr->non_const_method();
    const_foo_ptr->const_method();

    return 0;
}

But naming a typedef ConstRcPtr implies, to me, that the typedef would be

typedef const boost::shared_ptr<Foo> ConstRcPtr;

which is not what I'm interested in. An odder name, but maybe more accurate, is RcPtrConst:

typedef boost::shared_ptr<const Foo> RcPtrConst;

However, Googling for RcPtrConst gets zero hits, so people don't use this as a typedef name :)

Does anyone have any other suggestions?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost