[C++-sig] Re: Allocating objects on the heap by default.
David Abrahams
dave at boost-consulting.com
Tue Jul 8 23:01:33 CEST 2003
Prabhu Ramachandran <prabhu at aero.iitm.ernet.in> writes:
>>>>>> "DA" == David Abrahams <dave at boost-consulting.com> writes:
>
> >> How about holder(A, 'std::auto_ptr'), holder(A,
> >> 'boost::shared_ptr'), holder(A, 'user::smart_ptr').
>
> DA> I dislike that because it assumes too much about the way to
> DA> spell the smart pointer type: it would have to be of the form
> DA> 'pointer_name<PointeeName>', which rules out,
> DA> e.g. 'pointer_name<PointeeName, myAllocator>'.
>
> [snip]
> >> Internally the HeldType will add the right template parameter?
> >> But what if the smart pointer is not a templated class?
>
> DA> That's why I was suggesting
>
> DA> holder(class_ID, unary_callable)
>
> DA> The callable object is free to form the string any way it
> DA> likes.
>
> >> In that case we'd need to use something like this:
> >>
> >> holder(A, 'std::auto_ptr< %s >'), holder(A, 'user::smart_ptr').
> DA> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> DA> I don't understand what this part is illustrating.
>
> It is illustrating a user namespace with a smart_ptr class that is not
> templated. It does not matter.
>
> I don't see the point of the callable function. It only seems to
> complicate the interface.
Can you generate 'some_ptr<A,A>' with your interface?
> When writing Pyste files the user *will*
> know the name of the class and will know what smart pointer he/she
> wants to use. In that case I see nothing wrong with the user
> specifying the entire HeldType i.e. holder('std::auto_ptr<A>') or
> holder('pointer_name<PointeeName, myAllocator>') or whatever they
> choose.
Likewise, there's nothing wrong with skipping Pyste altogether and
using the direct Boost.Python C++ interface. Pyste is about providing
an even terser syntax for accomplishing the same things, and
'std::auto_ptr<A>' is not only longer but it repeats information.
Also, how will that interface work when you have a class with virtual
functions that you want to be held by auto_ptr?
> The callable function simply adds another unnecessary layer to this
> and ends up doing the same thing by generating a string that
> specifies the smart pointer.
No, it makes the syntax terser, makes the interface more flexible,
and works with polymorphic classes.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list