[C++-sig] Using boost::tuple from python

Jay Riley super24bitsound at hotmail.com
Sat Jun 25 20:40:35 CEST 2011

I've been trying to figure out how to expose a property in my class that is a boost::tuple. The tuple is defined as follows:

    typedef boost::shared_ptr<Action> action_ptr;
    typedef boost::tuple<BattleCharacter*, action_ptr > ActionTargetTuple;

It's contained with a class defined as follows:

    class Action : public Cloneable<Action>
              //Irrelevant Code Omitted
              std::vector<ActionTargetTuple> Targets;

I've seen numerous articles while I was searching about how to convert a boost::tuple into a python tuple, but that's not what I'm looking to do. I want to be able to access the tuple as it exists on the Action class. (I know how to do the vector part). The action class is exposed as follows:

            .def("Targets", &Action::Targets)

 I figured I might be able to expose the tuple by some variation on the below:

            .def("get", &ActionTargetTuple::get<int>, return_value_policy<reference_existing_object>())

then use get from python, but if it is doable in this way, I'm not sure what the set up needs to be. Does anyone know how to do this/could suggest an alternative?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110625/796e28b7/attachment.html>

More information about the Cplusplus-sig mailing list