DescriptionImplement scoped_const_refptr template.
The objectives of this hack are:
1. To make it possible to make good use of use const for refcounted
arguments that are not modified by the method/function.
2. Keep using the const scoped_refptr<Type>& style, to avoid refcount
updates for the call, but extend it const-declare the referred-to
object.
3. Not impose any additional storage or runtime overhead.
4. Make it possible to pass a |const scoped_refptr<Type>&| to a
function expecting a |const scoped_const_refptr<Type>&|, with
automatic type conversion, and *without* constructing any temporary
object.
The last requirement is the tricky one. It looks easy to just use
|const scoped_refptr<const Type>&|, but as far as I understand, this
would require a new temporary object and corersponding refcount
updates. The only way I've found (suggested by perkj) to get automatic
conversion and pass a reference to the same ptr object, is to
introduce scoped_const_refptr as a base class of scoped_ref_ptr.
And then requirement (3) implies that the sub class scoped_refptr must
use the same pointer member as the base class, using some ugly but
safe const casts.
All comments appreciated. It's not a really pure and kosher hack, but
I think the benefit, of being able to mark ref counted arguments as
const where appropriate, may be worth it.
Also note that for this to work, AddRef and Release most be const
methods, and the actual refcount declared as mutable. That's already
fixed for the main RefCountedObject base class, but needed some fixes
for older code.
As an initial test of the code, it is used for the source arguments to
some of the I420Buffer methods.
BUG=
Patch Set 1 #
Messages
Total messages: 6 (1 generated)
|