[C++-sig] init from free function instead of constructor

Roman Yakovenko roman.yakovenko at gmail.com
Fri Feb 2 21:43:58 CET 2007


On 2/2/07, Edson Tadeu <e.tadeu at gmail.com> wrote:
> I'm also getting the same errors when trying to wrap a "free" constructor
> returning by value for a class whose holder is itself.
>
> Inside detail::install_holder<T>::dispatch(Ptr x,
> mpl::false_), it is trying to access the type pointee<Ptr>::type, but Ptr is
> my own class and not a smart pointer, so the compiler gets angry with
> pointee_impl<false>::apply<T> trying to get T::element_type.
>
> Is there any fix for this or any solution that do not involve an ugly hack
> with heap allocation and converting back and forth between shared_ptr<>?

According to source ( http://tinyurl.com/3bddpf ) make_constructor function
should return raw pointer or an instance of a smart pointer.
The unit test( http://tinyurl.com/2oktkh ) confirms this.

It makes sense. Otherwise you will create 3 instances of the class:
1. The first instance within the  function
2. The instance, which will be created using copy-constructor, as
function return
    value
3. (I could be wrong here, I am not sure! ) Boost.Python allocate and
manage all
    instances of classes using heap. So here you will construct another instance
    on heap, using copy constructor.

I believe it is pretty simple to add functionality you want, but does
it worse that?

P.S. The documentation for the functionality could be improved, care
to submit a patch?

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list