【问题标题】:Boost.Python Multiple Return ArgumentsBoost.Python 多返回参数
【发布时间】:2015-07-08 14:05:36
【问题描述】:

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

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

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

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 来完成这个任务?

【问题讨论】:

  • 不幸的是,我认为没有更好的选择。在繁琐的过程中,我能想到的唯一能帮助您的是使用cog 为您自动生成函数(考虑到函数遵循相同的“模板”)。

标签: python c++ boost


【解决方案1】:

改进可能是:

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

【讨论】:

  • 请补充您的问题,说明改进之处。
猜你喜欢
  • 1970-01-01
  • 2014-08-25
  • 2010-12-06
  • 2014-03-17
  • 1970-01-01
  • 2013-02-25
  • 2013-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多