Why can't I replace std::map with std::unordered_map

后端 未结 2 1346
一向
一向 2020-12-02 00:14

This question might be a bit sketchy because I do not have the code available at home, but I know this thing otherwise will bug me the whole weekend.

When I tried to

2条回答
  •  孤街浪徒
    2020-12-02 00:34

    I guess that because std::unordered_map needs to rehash, and therefore copy elements, the types need to be complete, whereas a map, only ever working with pointers to elements, will not exhibit that problem.

    The solution here is to have an unordered map to a pointer:

    std::unordered_map >. 
    

提交回复
热议问题