I don't use Boost, but, by perusing the documentation, it looks to me
like you need to define your own intrusive_ptr_release(), or specialize
it, that takes a const ptr, and then does a const_cast<> on it.
I do not use boost either. It does not compile on my platform. But I use
my own smart pointers that have similar properties. But the main reason
why I spent no effort to make them compile is, that I need strong thread
safety and binary compatibility to const T*. Both is never provided by
boost.
But you say that a const_cast is safe in this case. Hopefully that's
true. I remember that there are different pointer aliasing rules for
const types. That might break compiler optimizations.
Yuk. I think that the lack of proper const support both in Boost, and in
C++11 is a glaring omission. Trying to force the templates to support
them, by passing a const class as the template class, doesn't really
work.
Sometimes it works well, but one can't cast the const away from the
const typename argument.
And I also think that the various _ptr-s have other issues too.
They may have drawbacks but they saved my backside many, many times too.
I think a better design is the one I used in LibCXX,
http://www.libcxx.org/refobj.html, with a separate ptr and const_ptr,
whose relationship is exactly equivalent to the relationship between
iterator and const_iterator, and with ptr being a subclass of const_ptr,
so that passing a ptr to a function that takes a const_ptr does not
involve construction of a temporary object.
Hmm, that might be another approach. Unfortunately much to type.
And I am not sure whether inheritance from the const pointer type is the
right answer since the base must have a member of const T* which have to
be doubled in the derived class by T* or many, many const_casts are
necessary.
I will check for that. However, i still need to invoke operator delete
for a const pointer type.
Marcel