I have a class that contains std::vector<Foo>, where Foois the class containing the key, value, comment, etc. Please note that there is a reason why I use a vector, not a dictionary.
I overloaded the index operator in C ++ foos["Key Name"]to do a vector search for the Foo object with the key matching "Key Name" (where foos- std::vector<Foo>).
I use SWIG to create a Python wrapper for my library, and I really want this subscript operator to expand in Python. In other words, I want to be able to use foos["Key Name"]to search for objects in a vector in Python.
Any tips on how to get SWIG to recognize the index operator and overload it in Python? I am a little surprised that I could not find examples of people who do this on the Internet. I think most people just use it std::map, and SWIG converts it to Python dict.
source
share