std::map default value

后端 未结 12 2051
旧巷少年郎
旧巷少年郎 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:56

    Maybe you can give a custom allocator who allocate with a default value you want.

    template < class Key, class T, class Compare = less,
           class Allocator = allocator > > class map;
    

提交回复
热议问题