简体   繁体   中英

How to convert a Python deque to a C++ container?

I have to pass a Python deque to a C++ function but I can't find any documentation on how to convert a deque to a C++ container (for this case, either a deque or a vector would do). Searched everywhere but I couldn't find a solution. There's gotta be a simple way to do this right? Thanks

There's no "simple way". You'll need to do that by hand (or maybe with some kind of interface generator), in a data-specific way.

Take a look at C API Introduction — Python 3.8.3 documentation for an overview of Python data model at C level. It has absolutely nothing to do with any C++ types.

You'll need to somehow extract the data you need from Python objects, via Python C API, and construct the C++ structure you need from that.

SWIG may help you here. Take a look at SWIG-4.0 Documentation -- it has a section about how to do conversion between C++ types and those from a scripting language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM