当我将其插入到无序图中时,向量的容量为0

问题描述 投票:1回答:2

我保留了一个大小为40的向量,但是当我将其作为一对插入无序映射中时,向量容量变为0。为什么是这样?

#include<vector> 
#include <iostream>
#include <unordered_map>
using namespace std;

int main() {
   std::vector<int> a;
   a.reserve(40);
   std::cout<<a.capacity()<<std::endl;

   std::unordered_map<int,vector<int>> _map;
   _map.insert(std::make_pair(1,a));
   std::cout<<_map[1].capacity()<<std::endl;



    return 0;
}
c++ c++11 vector unordered-map
2个回答
3
投票

make_pair将复制结构(6)一个新的向量which does not retain the capacity


1
投票

构造副本std::vector不需要保留构造副本的对象的容量。只需要保留内容。

© www.soinside.com 2019 - 2024. All rights reserved.