I'm trying to implement unordered_map> with using unordered_map::emplace
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main ()
{
unordered_map<char,vector<int>> amap;
amap.emplace('k',(2,9));
for(auto i : amap['k']){
cout << i;
}
}
I expected output as "99" because I constructed the vector with (2,9). but actual outcome was "000000000" which the emplace constructed vector as (9), 0 being default and 9 as number of ints. I played around little more with other parameter values and realized the emplace only took last value in vector parameter. Why is it?
I can still accomplish the goal by doing
vector<int> v(2,9);
amap.emplace('k',v);
but just wondering why, and save one line of code.