>any containers in C++ capable of that?
Sure, to a certain sanity point. It takes a little more work, but you can get a rough multi-keyed map using std::pair:
Code:
#include <iostream>
#include <map>
#include <utility>
namespace jsw {
struct compare {
bool operator()(const std::pair<int, int>& a, const std::pair<int, int>& b) const
{
if (a.first == b.first)
return a.first < b.first;
else
return a.second < b.second;
}
};
typedef std::map<std::pair<int, int>, std::pair<int, int>, compare> mymap_t;
std::pair<int, int> key(int k)
{
return std::make_pair(k, k);
}
std::pair<std::pair<int, int>, std::pair<int, int> > value(int k1, int k2, int v1, int v2)
{
return std::make_pair(std::make_pair(k1, k2), std::make_pair(v1, v2));
}
}
int main()
{
jsw::mymap_t m;
m.insert(jsw::value(1, 0, 1, 1));
m.insert(jsw::value(3, 5, 2, 6));
jsw::mymap_t::iterator it = m.find(jsw::key(5));
if (it != m.end())
std::cout<<"Found: ("<< it->second.first <<", "<< it->second.second <<")\n";
it = m.find(jsw::key(1));
if (it != m.end())
std::cout<<"Found: ("<< it->second.first <<", "<< it->second.second <<")\n";
it = m.find(jsw::key(0));
if (it != m.end())
std::cout<<"Found: ("<< it->second.first <<", "<< it->second.second <<")\n";
it = m.find(jsw::key(3));
if (it != m.end())
std::cout<<"Found: ("<< it->second.first <<", "<< it->second.second <<")\n";
}
Of course, tailoring it to your needs is up to you, but the standard containers are very powerful if you're willing to work for it.