boost::python: Python list to std::vector

后端 未结 4 2102
庸人自扰
庸人自扰 2020-12-24 01:47

Finally I\'m able to use std::vector in python using the [] operator. The trick is to simple provide a container in the boost C++ wrapper which handles the internal vector s

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 02:28

    To get automatic conversion from python lists, you have to define a converter, which

    1. checks if the list is convertible to your type (i.e. that it is a sequence; additionally, you can also check whether all elements are of required type, but that can be handled in the second step as well)
    2. returns the new object, if the first step succeeded; throw exception if a sequence element is not convertible to what you need.

    I can't find now anything else than my code, you can copy&paste this template (it is specialized at the end of that file for various contained types).

提交回复
热议问题