|
Boost : |
Subject: [boost] Interest in a protected pointer
From: Ray Logel (rlogel_at_[hidden])
Date: 2009-02-10 09:28:55
Is there any interest in pointer wrapper similar to scoped_ptr or
shared_ptr which can be used for pointer member variable which can the
referenced value can't be modified by non const functions? This class
wouldn't be responsible for any memory management and could have a
shared pointer version as well.
For example:
template<typename T>
class protected_ptr
{
T * ptr;
// ...
T * get();
const T * get() const;
// ... including operator* and operator->
}
class Foo
{
protected_ptr<Bar> _bar;
void Func1()
{
_bar->NonConstFunc();
_bar->ConstFunc();
}
void Func2() const
{
_bar->NonConstFunc(); // Compile error
_bar->ConstFunc(); // Ok
}
}
Ray Logel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk