wlav / cppyy

Other
391 stars 40 forks source link

No way to iterate over a unordered map. #125

Closed Fancyapplebee closed 1 year ago

Fancyapplebee commented 1 year ago

In CPPYY when you create a unordered_map there is no way to iterate over it in python. Because the add and sub dunders are not implemented the begin and end methods don't work.

wlav commented 1 year ago

Can you be more specific? Although std::unordered_map isn't Pythonized (something that can be fixed), begin() and end() seem to work fine and add is accessible. Example:

import cppyy

std = cppyy.gbl.std

m = std.unordered_map[std.string, std.string]()

for key, value in (("aap", "noot"), ("zus", "mies")):
    m[key] = value

b = m.begin()
while b != m.end():
    print(b.first, b.second)
    b.__postinc__(1)
wlav commented 1 year ago

Pythonization has been added to repo.

Fancyapplebee commented 1 year ago

Your solution worked! Thanks.