gpt4 book ai didi

python - Boost.Python 多重返回参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:01:30 24 4
gpt4 key购买 nike

我有一个 C++ 函数,它从它的参数返回多个值。

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

我想用 Boost.Python 包装这个函数。我想出了一个使用 lambda 的解决方案,但它有点乏味,因为我有许多函数在其参数中有多个返回值。

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

是否有更好的\自动的方法来使用 Boost.Python 完成此任务?

最佳答案

改进可能是:

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

关于python - Boost.Python 多重返回参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295122/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com