Why the following code compiles with `C ++ 03`, but not with` C ++ 11`

I use the library boost::pythonin this tiny mwe.

#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);

} 

I noticed that the above code compiles with std=c++03and gnu++03, but not with c++11or c++0x. Error:

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)

My boost boost: stable 1.60.0, and my g ++ - g++-mp-5 (MacPorts gcc5 5.4.0_0) 5.4.0. I see that somehow the new standard is causing type / pattern problems, but to be honest, I really don't understand why? Is the problem that Boost just wasn't tested with C ++ 11? What exactly does the error message above mean?

+4
source share
2 answers

The error message gives you the key:

std::deque::push_back. reference, :

void push_back( const T& value );
void push_back( T&& value ); // (since C++11)

++ 11 ​​ . . push_front. , ++ 11 [].

:

.def("push_back"  ,static_cast<void(DequeUInt64::*)(DequeUInt64::const_reference)>(&DequeUInt64::push_back))
.def("push_front" ,static_cast<void(DequeUInt64::*)(DequeUInt64::const_reference)>(&DequeUInt64::push_front))

, STL .

, , Tanner:

.def("push_back"  ,+[](DequeUInt64* d, DequeUInt64::const_reference x) { return d->push_back(x); })
.def("push_front" ,+[](DequeUInt64* d, DequeUInt64::const_reference x) { return d->push_front(x); })
+8

, ++ 11 push_back , .. void push_front( T&& value );

, (<unresolved overloaded function type>). , :

boost::python::class_<DequeUInt64>("DequeUInt64")
.def<void (DequeUInt64::*)( const T&)>("push_back",&DequeUInt64::push_back)
+4

Source: https://habr.com/ru/post/1648843/


All Articles