Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Python Multiple Return Arguments

Tags:

c++

python

boost

I have a C++ function that returns multiple values from its arguments.

void Do_Something( double input1, double input2, double input3,
    double& output1, double& output2 )
{
    ...
    output1 = something;
    output2 = something;
}

I want to wrap this function using Boost.Python. I've come up with a solution using lambdas, but its sort of tedious since I have many functions that have multiple return values in their arguments.

BOOST_PYTHON_MODULE( mymodule )
{
    using boost::python;
    def( "Do_Something", +[]( double input1, double input2, double input3 )
    {
        double output1;
        double output2;
        Do_Something( input1, input2, input3, output1, output2 );
        return make_tuple( output1, output2 );
    });
}

Is there a better\automatic way to do accomplish this with Boost.Python?

like image 225
csnate Avatar asked Jul 08 '15 14:07

csnate


1 Answers

An improvement could be:

boost::python::tuple Do_Something(double input1, double input2,
                                  double input3) {
    // Do something
    ...
    return boost::python::make_tuple(output1, output2);
}

BOOST_PYTHON_MODULE(mymodule) {
    def("Do_Something", Do_Something);
}
like image 126
yeeac Avatar answered Oct 01 '22 19:10

yeeac