We have a C++ API where a core feature is an std::map<string, SomeObject>. (For the purposes of this discussion, the type of SomeObject doesn't matter. It could be as simple as int.)
We'd like to write a Swift API that gives the developers access to this library; it would be great if our "bridge" to this std::map looked like it was exposing a collection similar to a Swift dictionary.
The first thing I notice about writing something that conforms to collection is that you be able to do certain operations in O(1) time. In particular, given an index, you have to be able to jump to that location quickly. This is fundementally at odds with std::map where you can't compute distances between elements, or jump any place really. Is a class which wraps std::map with something which satisfies the collection protocol just a non-starter? I'm thinking about how to do this and just hitting a blank wall.
The other question is that a collection doesn't say anything about looking things up by a specific key. Is there a protocol layer i'm missing that talks about using a key type to get to a value? Or is that just built into Dictionary, and there's not a protocol which has this property i could conform to?