[C++-sig] Re: Dereferenceable concept proposal
David Abrahams
dave at boost-consulting.com
Thu Nov 6 22:22:49 CET 2003
Pierre Barbier de Reuille <pierre.barbier at cirad.fr> writes:
> In the project I'm working on, we are using intrusive smart pointers.
> When trying to export classes used with such smart pointers, I had a
> problem with the dereferenceable concept. This concept require the
> existence of a 'get' method, but the smart pointer we use does not have
> this method (ie. the method exists but with another name). We cannot
> rename the method for it will break to many code, and not only code from
> us. So, would it be possible to replace this requirement by something
> like having an expression :
>
> get_pointer_from_smart_pointer()( smart_pointer )
>
> get_pointer_from_smart_pointer being a template with this default
> definition :
>
> template <class T>
> struct get_pointer_from_smart_pointer
> {
> typename pointee<T>::type* operator()(const T& ptr) const
> {
> return ptr.get();
> }
> }
>
> This way, it should not break the existing code and we should be able to
> use uour smart pointer by just redefining this class.
Doh!
How could I have been so stupid?
I know better than to design a generic interface that depends on
member functions, really I do!
The right thing to do would've been to rely on
htpp://www.boost.org/libs/bind/mem_fn.html#get_pointer
http://www.boost.org/libs/smart_ptr/shared_ptr.htm#get_pointer
[Peter, I note that there's no specification of get_pointer for
scoped_ptr, and it doesn't appear in
http://www.boost.org/libs/smart_ptr/smart_ptr.htm#common_requirements
either. Oversight?]
> The main problem is, I'm not really able to evaluate the changes needed
> in the Boost.Python code.
Just do a grep for "[>\.]get()" and you should find all the instances
that should be changed to get_pointer. There's a function called
is_null that could be completely eliminated. I'd appreciate a patch!
> And perhaps this solution has tons of defaults I don't see :-/
Do you mean "implications", perhaps?
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list