Boost.Python Multiple Return Arguments

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 came up with a solution using lambdas, but it's kind of tedious since I have a lot of 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 this with Boost.Python?

+3


source to share


1 answer


Improvement can 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);
}

      

+1


source







All Articles