Boost logo

Boost Users :

From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2007-09-20 15:10:20


Hi,

In my new company we are using Boost.Python. Boost version is 1.33.1.

It's my first steps with the library, so please bare with me if this is
something trivial.

I've got this noncopyable class Foo

class Foo : boost::noncopyable { /*...*/ };

and shift operator defined:

Foo&
operator<<( Foo& foo, int )
{
    ...
    return foo;
}

Here is my export statement (FooSP is smart pointer on Foo

using namespace boost::python;

class_<Foo, FooSP, bases<FooBase>, boost::noncopyable>( "Foo", no_init )
        .def( self << int() )
        ;

Here is my Python script extract that is being executed from C++

"foo << 2 << 4"

I never got to the second shift call. Instead I an getting exception from
Boost.Python:

TypeError: No to_python (by-value) converter found for C++ type: class A

I kinda found couple ways to deal with it:

1. define operator<< to return FooSP, which I do not like for assymetry and
other reasons
2. avoid using self << int() and define explicit function:
Foo&
shift_op( Foo& foo, int )
{
    ...
    return foo;
}

...
   .def( "__lshift__", &shift_op, return_internal_reference<1>() )

What is the proper way to deal with it? And why original error is reported?

Gennadiy


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net