C++ Mapping for Dictionaries

On this page:

Default Dictionary Mapping in C++

Here is the definition of our EmployeeMap once more:

Slice
dictionary<long, Employee> EmployeeMap;

The following code is generated for this definition:

C++
typedef std::map<Ice::Long, Employee> EmployeeMap;

Again, there are no surprises here: a Slice dictionary simply maps to a standard std::map. As a result, you can use the dictionary like any other map, for example:

C++
EmployeeMap em;
Employee e;

e.number = 42;
e.firstName = "Stan";
e.lastName = "Lippman";
em[e.number] = e;

e.number = 77;
e.firstName = "Herb";
e.lastName = "Sutter";
em[e.number] = e;

Custom Dictionary Mapping in C++

You can override the default mapping of Slice dictionaries to C++ maps with a cpp:type  a or cpp:view-type metadata directive, for example:

Slice
[["cpp:include:unordered_map"]]

["cpp:type:std::unordered_map<Ice::Long, Employee>"] dictionary<long, Employee> EmployeeMap;

With this metadata directive, the dictionary now maps to a C++ std::unordered_map:

C++
#include <unordered_map>

typedef std::unordered_map<Ice::Long, Employee> EmployeeMap;

See Customizing the C++ Mapping for detailed information about the cpp:type and cpp:view-type metadata directives.

See Also