Looking for an example to bind std::deque, Thanks! #4292
-
Example:
Bind:
But I got error: "error: 'bind_deque' is not a member of 'py'." I thought binding deque should be similar to binding vector or map (py::bind_vector<std::vector). |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Assuming you have a caster made for sampel We don't have any casters for std::deque written in stl_bind.h. STL bind_vector and bind_map are the only two implement in stl_bind.h. Otherwise, you would need to bind all the methods yourself manually. |
Beta Was this translation helpful? Give feedback.
-
@Skylion007 , thank you for your attention. You mean std::deque should work out of box, correct? I've tried that (no binding code for it), but when I run my test script ( the std::deque is a return type for another function), I got error saying " TypeError: Unable to convert runction return value to a Python type! The signature was\n\t() -> List[namespace::SampleType]\n\n At:\n /tmp/test.py(472): func_test1\n\n" |
Beta Was this translation helpful? Give feedback.
-
@ffyu-lj Not unless you define a caster for SampleType. If it was an std::tuple or std::pair, it woudl work. Or you need to go and create a custom caster for SampleType or bind SampleType as a Python class |
Beta Was this translation helpful? Give feedback.
Assuming you have a caster made for sampel
SampleType
, you should includepybind/stl.h
and that will give you a std::deque caster automatically. Alternatively,std::deque<std::pair<int,std::string>>
should work out of the box as a non-opaque caster.We don't have any casters for std::deque written in stl_bind.h. STL bind_vector and bind_map are the only two implement in stl_bind.h. Otherwise, you would need to bind all the methods yourself manually.