Archived

This forum has been archived. Please start a new discussion on GitHub.

Nested structs in key types for Slice dictionaries

Hi,

The Ice Manual > The Slice Language > User-Defined Types > Dictionaries > Allowable Types for Dictionary Keys and Values section (at Dictionaries - Ice 3.5 - ZeroC) says that the key type of a dictionary is limited to one of the following types:
- Integral types (byte, short, int, long, bool)
- string
- enum
- Structures containing only data members of integral type or string

Complex nested types, such as nested structures, sequences, or dictionaries, and floating-point types (float and double) cannot be used as the key type.

I am using Ice 3.5 and have defined a dictionary as follows:
struct NodeKey {
string name; // The node name.
};

struct InterfaceKey {
NodeKey sourceKey; // The node key
string name; // The interface name
};

/** A map from interface keys to interfaces. **/
dictionary<InterfaceKey, Iface*> InterfaceMap;

This compiles and works fine though the dictionary key contains a nested structure (NodeKey within the InterfaceKey).

Is this something that can be relied upon to work with Ice if the leaf-level structure (within the nesting) only contains members of integral/string/enum types? Will multi-level nesting of structs also work for dictionary keys?

We are using Ice with C++, Java and Python as the intended target languages.

Thanks,
Shankar

Comments

  • mes
    mes California
    Hi,

    Welcome to the forum.

    Thanks for pointing this out. The manual's wording is overly restrictive, a struct's data members just need to be legal key types (recursively), and this has been true for a long time. I've updated the manual.

    Regards,
    Mark