我是python的新手,我看过boost python,它看起来非常令人印象深刻.然而,通过介绍我找不到任何示例,对象的向量作为python列表/元组返回.
即举个例子,我想公开类X,Cont及其所有函数.关键位返回X的向量或字符串到python
class X {};
class Cont {
.....
// how can this be exposed using boost python
const std::vector<X>& const_ref_x_vec() const { return x_vec_;}
std::vector<X> value_x_vec() const { return x_vec;}
const std::vector<std::string>& const_ref_str_vec() const { return str_vec_;}
std::vector<std::string> value_str_vec() const { return str_vec_; }
...
private:
std::vector<X> x_vec_;
std::vector<std::string> str_vec_;
};
Run Code Online (Sandbox Code Playgroud)
我尝试公开const_ref_x_vec(),value_x_vec()等函数的无效尝试只会导致编译错误.
从谷歌搜索我没有看到任何支持按值或引用返回向量的示例.使用boost python甚至可以实现这一点吗?有没有解决方法?我应该在这种情况下使用SWIG吗?
任何帮助赞赏.
Avtar
boost-python ×1