std::map default value

后端 未结 12 2073
旧巷少年郎
旧巷少年郎 2020-11-28 06:09

Is there a way to specify the default value std::map\'s operator[] returns when an key does not exist?

12条回答
  •  悲哀的现实
    2020-11-28 06:55

    While this does not exactly answer the question, I have circumvented the problem with code like this:

    struct IntDefaultedToMinusOne
    {
        int i = -1;
    };
    
    std::map mymap;
    

提交回复
热议问题