Resolve "pybind11:接口中存在 vector | map 容器引用为参数时,并没有达到引用的效果"
Closes #404 (closed)
- 收集接口中出现过的
vector | map实例化容器引用类型 - 生成
pybind11_opaque.hpp文件调用PYBIND11_MAKE_OPAQUE(T),用于消除pybind11/stl_bind.hpp中对实例化容器类型T的自动cast。对于引用了pybind11/stl_bind.hpp的位置都需要同时引用pybind11_opaque.hpp,否则会出现映射错误 - 在
binder接口(绑定接口统一调用入口)中调用bind_vector<T, name>,pybind11::bind_map<T, name>,完成容器的引用语义自动绑定。(pybind11不支持set的引用语义自动绑定) - 在接口参数,返回值,变量翻译中,针对收集的实例化容器类型进行区分绑定:
a. 若为
vector&,map&采用引用语义绑定; b. 若为vector,map,const vector &, const map &,则用lambda函数包装原生接口,使用pybind11::list或pybind11::dict类型绑定cppvector或map类型 - 对于模板嵌套类型,如
std::vector<std::vector<std::string>>>,其中模板参数类型std::vector<std::string>>,会被翻译为默认类型,即若std::vector<std::string>>默认绑定为ListString,则std::vector<std::vector<std::string>>>&被翻译为ListListString, 内部储存ListString;std::vector<std::vector<std::string>>>和const std::vector<std::vector<std::string>>> &被翻译为list[ListString]
Edited by mingfa.yang