Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #282 Use a custom type as map key

Declare a type Foo, and create a new map with Foo as key type.

Mention the conditions on Foo required to make it a possible map key type.

class Foo{};
Map<Foo, int> m = {};

note that typedef can also be used to declare a type, ex: typedef Foo = List<int>;

New implementation...
< >
programming-idioms.org