Several times I have run into a use case where I have some object that I
would like to access via something like a std::map<>, but which already
contains a member that I would like to use as a key. Is there any data
structure that "acts like a map", but instead of storing
std::pair allows me to store an object directly, and specify
what member of that object is the key value?
I can give a specific use case for this:
For those of you not familiar with the SCA, there is an object called
CF::Properties. This is a CORBA sequence (think std::vector) of objects
of {string name, CORBA::Any value}, used to store metadata. Ideally, I'd
like to have an object that I could initialize from that sequence that
would allow me to do things like this:
inline string &getKey(CF::Property &x)
{
return x.name;
}
void foo(CF::Properties &meta)
{
mapLikeThingCF::Property,getKey myMap(meta);
double sampleRate;
myMap["SampleRate"] >> sampleRate;
setHardwareSampleRate(sampleRate);
}