I'm trying to use the std::map
's []
operator with a custom key type:
typedef tuple<DWORD, DWORD, DWORD, DWORD> Version; // Key type
const map<Version, string> codenames {
{ {3,0,1,5}, "Maserati" },
{ {3,0,2,6}, "Elephant" }
};
Version ver{3,0,2,6};
string codename = codenames[ver];
// Error C2678 binary '[': no operator found which takes a left-hand operand of type '...' (or there is no acceptable conversion)
string codename = codenames[{3,0,2,6}];
// Same error
Is it possible to access the values using the []
operator with that custom key type? I'm using Visual Studio 2015 Update 3.
PS:
The question: std::maps with user-defined types as key is not a duplicate, because it's not related to the []
operator and doesn't answer this question.