当提前知道大小时,初始化std :: map [英] Initializing a std::map when the size is known in advance
本文介绍了当提前知道大小时,初始化std :: map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想初始化一个 std :: map
。现在我使用 :: insert
,但是我觉得我在浪费一些计算时间,因为我已经知道我想要分配的大小。有没有办法分配固定大小的地图,然后填写地图?
I would like to initialize a std::map
. For now I am using ::insert
but I feel I am wasting some computational time since I already know the size I want to allocate. Is there a way to allocate a fixed size map and then fill the map ?
推荐答案
不,地图的成员在内部存储在树结构中。在知道要存储的键和值之前,没有办法构建树。
No, the members of the map are internally stored in a tree structure. There is no way to build the tree until you know the keys and values that are to be stored.
这篇关于当提前知道大小时,初始化std :: map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文