#include <iostream>
#include <string>
#include <tuple>
#include <utility>
#include <unordered_map>
namespace N {
typedef std::tuple<std::string,int,char> key_t;
struct key_hash : public std::unary_function<key_t, std::size_t>
{
std::size_t operator()(const key_t& k) const
{
return std::get<0>(k)[0] ^ std::get<1>(k) ^ std::get<2>(k);
}
};
struct key_equal : public std::binary_function<key_t, key_t, bool>
{
bool operator()(const key_t& v0, const key_t& v1) const
{
return (
std::get<0>(v0) == std::get<0>(v1) &&
std::get<1>(v0) == std::get<1>(v1) &&
std::get<2>(v0) == std::get<2>(v1)
);
}
};
struct data
{
std::string x;
};
typedef std::unordered_map<const key_t,data,key_hash,key_equal> map_t;
}
int main()
{
using namespace N;
map_t m;
data d;
d.x = "test data";
m[std::make_tuple("abc",1,'X')] = d;
auto itr = m.find(std::make_tuple(std::string("abc"),1,'X'));
if (m.end() != itr)
{
std::cout << "x: " << itr->second.x;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KCm5hbWVzcGFjZSBOIHsKCnR5cGVkZWYgc3RkOjp0dXBsZTxzdGQ6OnN0cmluZyxpbnQsY2hhcj4ga2V5X3Q7CgpzdHJ1Y3Qga2V5X2hhc2ggOiBwdWJsaWMgc3RkOjp1bmFyeV9mdW5jdGlvbjxrZXlfdCwgc3RkOjpzaXplX3Q+CnsKICAgc3RkOjpzaXplX3Qgb3BlcmF0b3IoKShjb25zdCBrZXlfdCYgaykgY29uc3QKICAgewogICAgICByZXR1cm4gc3RkOjpnZXQ8MD4oaylbMF0gXiBzdGQ6OmdldDwxPihrKSBeIHN0ZDo6Z2V0PDI+KGspOwogICB9Cn07CgpzdHJ1Y3Qga2V5X2VxdWFsIDogcHVibGljIHN0ZDo6YmluYXJ5X2Z1bmN0aW9uPGtleV90LCBrZXlfdCwgYm9vbD4KewogICB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