繁体   English   中英

如何导出向量 <T> :: push_back返回Python?

[英]How can I export vector<T>::push_back to Python?

这个问题很简单,我会误解一些琐碎的东西。 但是由于我几个小时都找不到解决方案,请在这里让我问一个问题。

我想做的是使用Boost.Python将std::vector<T>容器类的push_back方法(带有一些固定类型T (例如double ))导出到Python。

为此,我编写了以下代码:

typedef std::vector<double> vector_double;
class_<vector_double>("vector_double")
    .def("append", &vector_double::push_back);

但这不会与以下错误一起编译:

/Users/kenta/experiments/bisite/include/bisite/conservation_score.hpp:25:7: note:
      candidate constructor (the implicit default constructor) not viable:
      requires 0 arguments, but 1 was provided
/Users/kenta/experiments/bisite/src/bisite/pybisite.cpp:90:10: error: no
      matching member function for call to 'def'
        .def("append", &vector_double::push_back);
        ~^~~
/usr/local/include/boost/python/class.hpp:234:11: note: candidate template
      ignored: couldn't infer template argument 'F'
    self& def(char const* name, F f)
          ^
/usr/local/include/boost/python/class.hpp:224:11: note: candidate function
      template not viable: requires single argument 'visitor', but 2 arguments
      were provided
    self& def(def_visitor<Derived> const& visitor)

... and more candidates

类型推导(?)似乎失败了,但我不知道为什么。 当我将vector_double定义为std::vector<double>的子类时,以上代码已成功编译。 但由于某些原因,我不想这样做。

您能教我解决这个问题的方法吗?

我正在使用带有-std=c++11选项和Boost.Python v1.56.0的clang ++。

谢谢。

在我看来,问题在于C ++ 11中有两个版本的push_back 尝试这样做

static_cast<void (vector_double::*)(const double&)>(&vector_double::push_back);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM