Reference as key in std::map

后端 未结 4 745
傲寒
傲寒 2021-02-07 12:39

Suppose some data structure:

typedef struct {
    std::string s;
    int i;
} data;

If I use the field data.s as key when adding i

4条回答
  •  时光取名叫无心
    2021-02-07 12:53

    I don't think there's a big performance gain if you choose pointer instead of object. Only do this if you're managing data with lot of existing string objects which need to hold inside the container. Also the destruction of the objects has to be managed manually before destructing the container.

提交回复
热议问题