首页 > 解决方案 > 提升地图的python向量..(结构)..不走运

问题描述

尝试公开具有以下类型的映射向量(键是字符串,值是结构对象):

// boost includes ..

struct MyStruct {
  double a;
  vector<double> vec;
  bool operator==(const MyStruct& other) {return false;}
  bool operator!=(const MyStruct& other) {return true;}
};

typedef map<string, MyStruct>      MyMap;

typedef vector<MyStruct>           MyVec;
typedef vector<MyMap>              MyVec2;

BOOST_PYTHON_MODULE(_axstatistics)
{

    py::class_<MyStruct>("MyStruct")
        .def_readwrite("a", &MyStruct::a)
        .def_readwrite("vec", &MyStruct::vec)
        ;

    py::class_<MyMap>("MyMap")
        .def(map_indexing_suite<MyMap>());

    py::class_<MyVec>("MyVec")
        .def(vector_indexing_suite<MyVec>());

// uncomment and boum
//    py::class_<MyVec2>("MyVec2")
//        .def(vector_indexing_suite<MyVec2>());

}

这适用于MyVec但不适用于MyVec2,我得到一个几乎不可读的编译错误。

有人对这种模式有想法或有经验吗?

提前谢谢..

标签: pythonvectorbooststructmaps

解决方案


通过在and类上定义==运算符来运行它。MyMapMyVec2


推荐阅读