Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pybind11:如何绑定C++;用于执行到std::vector的隐式类型转换的模板函数<;T>;功能? 我有以下C++模板函数: template<typename T> std::vector<T> add_two_columns(std::vector<T> vec1, std::vector<T> vec2) { vec2.resize(vec1.size()); std::transform(vec1.begin(), vec1.end(), vec2.begin(), vec1.begin(), std::plus<T>()); return vec1; }_Python_C++_Casting_Stdvector_Pybind11 - Fatal编程技术网

Python pybind11:如何绑定C++;用于执行到std::vector的隐式类型转换的模板函数<;T>;功能? 我有以下C++模板函数: template<typename T> std::vector<T> add_two_columns(std::vector<T> vec1, std::vector<T> vec2) { vec2.resize(vec1.size()); std::transform(vec1.begin(), vec1.end(), vec2.begin(), vec1.begin(), std::plus<T>()); return vec1; }

Python pybind11:如何绑定C++;用于执行到std::vector的隐式类型转换的模板函数<;T>;功能? 我有以下C++模板函数: template<typename T> std::vector<T> add_two_columns(std::vector<T> vec1, std::vector<T> vec2) { vec2.resize(vec1.size()); std::transform(vec1.begin(), vec1.end(), vec2.begin(), vec1.begin(), std::plus<T>()); return vec1; },python,c++,casting,stdvector,pybind11,Python,C++,Casting,Stdvector,Pybind11,这将导致以下错误: src/main.cpp: In function ‘void pybind11_init_py_pkg(pybind11::module&)’: src/main.cpp:173:80: error: no matching function for call to ‘pybind11::module::def(const char [16], <unresolved overloaded function type>, const char [32])

这将导致以下错误:

src/main.cpp: In function ‘void pybind11_init_py_pkg(pybind11::module&)’:
src/main.cpp:173:80: error: no matching function for call to ‘pybind11::module::def(const char [16], <unresolved overloaded function type>, const char [32])’
     m.def("add_two_columns", add_two_columns, "Add two Integer columns/vectors");

In file included from src/main.cpp:1:0:
/home/username/miniconda3/envs/speedup/include/python3.6m/pybind11/pybind11.h:818:13: note: candidate: template<class Func, class ... Extra> pybind11::module& pybind11::module::def(const char*, Func&&, const Extra& ...)
     module &def(const char *name_, Func &&f, const Extra& ... extra) {
             ^~~
/home/username/miniconda3/envs/speedup/include/python3.6m/pybind11/pybind11.h:818:13: note:   template argument deduction/substitution failed:
src/main.cpp:173:80: note:   couldn't deduce template parameter ‘Func’
     m.def("add_two_columns", add_two_columns, "Add two Integer columns/vectors");
                                                                                ^
error: command 'gcc' failed with exit status 1
src/main.cpp:在函数“void pybind11_init_py_pkg(pybind11::module&)”中:
src/main.cpp:173:80:错误:调用'pybind11::module::def(const char[16],const char[32])时没有匹配的函数
m、 def(“添加两列”、“添加两列”、“添加两个整数列/向量”);
在src/main.cpp中包含的文件中:1:0:
/home/username/miniconda3/envs/speedup/include/python3.6m/pybind11/pybind11.h:818:13:注:候选:模板pybind11::module&pybind11::module::def(const char*,Func&&,const Extra&…)
模块和定义(常量字符*名称、函数和函数、常量额外和…额外){
^~~
/home/username/miniconda3/envs/speedup/include/python3.6m/pybind11/pybind11.h:818:13:注意:模板参数扣除/替换失败:
src/main.cpp:173:80:注意:无法推断模板参数“Func”
m、 def(“添加两列”、“添加两列”、“添加两个整数列/向量”);
^
错误:命令“gcc”失败,退出状态为1
我查看了此文档,但不了解如何调用或绑定模板函数:

template<typename T>
std::vector<T> add_two_columns(std::vector<T> vec1, std::vector<T> vec2) {
    vec2.resize(vec1.size());
    std::transform(vec1.begin(), vec1.end(), vec2.begin(), vec1.begin(), std::plus<T>());
    return vec1;
}

您需要为您关心的所有类型显式实例化
添加两列
,并添加这些显式实例化。例如,绑定
添加两列
等。您需要为您关心的所有类型显式实例化
添加两列
,并添加这些显式实例化。例如,绑定
添加两列列
等。