Boost logo

Boost :

Subject: Re: [boost] [c++-sig]Python binding for templated constructor
From: Jim Bosch (talljimbo_at_[hidden])
Date: 2010-05-26 00:23:57

On 05/25/2010 01:58 PM, Sandeep Gupta wrote:
> Hi,
> I have a class with a generic constructor as follows :
> class X
> {
> indexes m_idx;
> template<class strategy>
> X(){
> build_indexes<strategy>()
> };
> My problem is that I am not able to figure out the syntax to export this
> constructor. Is the above class not well defined ?.

That's a good question. I'm not sure if it's possible using
boost::python::init, but here's a possible workaround:

namespace bp = boost::python;

template <typename strategy>
static X construct_X() { // could also return registered smart pointer to X.
     return X<strategy>();

     bp::class_<X>("X", bp::no_init) // no_init keeps bp from trying to
call default ctor

I haven't tested that, but I think it should work. By the way, you'll
get more responses to Boost.Python questions at the Python/C++-sig
mailing list:


Hope that helps!

Jim Bosch

Boost list run by bdawes at, gregod at, cpdaniel at, john at