Collections galore!
I'm a big fan of Java generics, ie List<type>. I'm also a big fan of C++ templates of the same ilk, ie std::list<type>. I'm finding myself in a sort of quandary, at the moment. I find myself needing to keep some data together, in a fairly unstructured format, so a list is great. Here's what I'm doing at the moment:
std::list< pair<std::string, myType> >;
Fairly standard fair as far as collections go. Something many of us use every day, probably more than a handful of times. Okay, so that's the basics. I also need to keep track of the pair<> item by name, the string parameter. So I could do the following:
std::map<std::string, myType> ;
That's also something fairly easy to accomplish, and something many of us do fairly frequently - like the list, the map is one of the basic datastructures. Okay, here's where things get difficult - I *ALSO* need to have a unique id to this pair of objects, a key if you will. I could use the return value from std::string::c_str(). Here, though, I risk that a side effect of a copy constructor could change the underlying char* of my string value. I could use a hash of the std::string itself, but sometimes I may want to allow collisions, maybe myType is the unique differentiator in this pair<>.
How do I solve this problem? How do I make indexed maps? Well it appears that people far smarter than I have already run into this problem and come up with a solution for it:
This is a Boost-based STL-type container that lets me specify a base container, as well as a number of index access mechanisms. I'm excited to try it out!