Generated 'item' type is always std::pair for map containers

Bug #798475 reported by John Pursey
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyBindGen
Confirmed
Low
Gustavo Carneiro

Bug Description

The generated code for any "map" like container always uses a std::pair. We have an alternate STL implementation in its own namespace and so std::pair<> is incompatible for our map class. In any case, it is more portable to use the map<K,V>::value_type instead as it will always map to the correct type. The current code and proposed change are below:

-------------- CURRENT ---------------
            std::pair<%(KEY_CTYPE)s, %(ITEM_CTYPE)s> item;
            if (!%(KEY_CONVERTER)s(PyTuple_GET_ITEM(tup, 0), &item.first)) {
                return 0;
            }
            if (!%(ITEM_CONVERTER)s(PyTuple_GET_ITEM(tup, 1), &item.second)) {
                return 0;
            }

-------------- PROPOSED ---------------
            %(KEY_CTYPE)s key;
            %(ITEM_CTYPE)s value;
            if (!%(KEY_CONVERTER)s(PyTuple_GET_ITEM(tup, 0), &key)) {
                return 0;
            }
            if (!%(ITEM_CONVERTER)s(PyTuple_GET_ITEM(tup, 1), &value)) {
                return 0;
            }
            %(CTYPE)s::value_type item(key,value);

Revision history for this message
Gustavo Carneiro (gjc) wrote :

I would rather avoid the key and value temp vars, if possible, for the sake of efficiency. Question, can we assume %(CTYPE)s::value_type always has a 'first' and 'second', like std::pair, at least?

Changed in pybindgen:
status: New → Confirmed
importance: Undecided → Low
assignee: nobody → Gustavo Carneiro (gjc)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.