【发布时间】:2016-07-22 23:54:23
【问题描述】:
我在这个小小的 mwe 中使用 boost::python 库。
#include <deque>
#include <boost/python.hpp>
typedef std::deque<long unsigned int> DequeUInt64;
BOOST_PYTHON_MODULE_INIT(tmp) {
boost::python::class_<DequeUInt64>("DequeUInt64")
.def("push_back" ,&DequeUInt64::push_back)
.def("push_front" ,&DequeUInt64::push_front);
}
我观察到上面的代码可以使用std=c++03 和gnu++03 编译,但不能使用c++11 或c++0x。错误是:
tmp.cpp: In function 'void init_module_tmp()':
tmp.cpp:8:47: error: no matching function for call to 'boost::python::class_<std::deque<long unsigned int> >::def(const char [10], <unresolved overloaded function type>)'
.def("push_back" ,&DequeUInt64::push_back)
^
In file included [from /opt/local/include/boost/python.hpp:18:0], [from tmp.cpp:2]:
/opt/local/include/boost/python/class.hpp:223:11:
note: candidate:
template<class Derived> boost::python::class_<T, X1, X2, X3>::self&
boost::python::class_<T, X1, X2, X3>::def(const boost::python::def_visitor<Derived>&)
[with Derived = Derived;
W = std::deque<long unsigned int>;
X1 = boost::python::detail::not_specified;
X2 = boost::python::detail::not_specified;
X3 = boost::python::detail::not_specified]
self& def(def_visitor<Derived> const& visitor)
^
note: template argument deduction/substitution failed:
tmp.cpp:8:47:
note: mismatched types 'const boost::python::def_visitor<U>' and 'const char [10]'
.def("push_back" ,&DequeUInt64::push_back)
^
In file included [from /opt/local/include/boost/python.hpp:18:0], [from tmp.cpp:2]:
/opt/local/include/boost/python/class.hpp:233:11:
note: candidate:
template<class F> boost::python::class_<T, X1, X2, X3>::self&
boost::python::class_<T, X1, X2, X3>::def(const char*, F)
[with F = F;
W = std::deque<long unsigned int>;
X1 = boost::python::detail::not_specified;
X2 = boost::python::detail::not_specified;
X3 = boost::python::detail::not_specified]
self& def(char const* name, F f)
^
note: template argument deduction/substitution failed:
tmp.cpp:8:47:
note: couldn't deduce template parameter 'F'
.def("push_back" ,&DequeUInt64::push_back)
我的 boost 是 boost: stable 1.60.0,我的 g++ 是 g++-mp-5 (MacPorts gcc5 5.4.0_0) 5.4.0。我可以看到,新标准不知何故导致类型/模板推断出现问题,但老实说,我真的不明白为什么?问题是因为 Boost 根本没有用 c++11 测试过吗?无论如何,上面的错误消息到底是什么意思?
【问题讨论】:
-
只是出于好奇,Clang 有效吗?
-
我很惊讶这个问题只有 2 票。除了标题含糊不清之外,这个问题包含了我想要的一切:一个实际的 MCVE、一个完整的编译器错误和上下文(Boost 和编译器版本)。
标签: c++ c++11 boost boost-python