Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how could I initialize unordered_map< vector<int> >?

I met a question in my work

There is an unordered_map on vector<int> in my c++ class
like this unordered_map < int, vector<int> >

so how could I initialize the nested container so that when I insert a key to the hash table and the value(vector) will be ten zero ?

like image 318
Papulatus Avatar asked Sep 17 '26 02:09

Papulatus


1 Answers

You can use list initialization:

std::unordered_map<int, std::vector<int>> m
  { { 2, std::vector<int>(10, 0) }
  , { 5, std::vector<int>(10, 0) }
  , { 6, std::vector<int>(10, 0) }
  , { 9, std::vector<int>(10, 0) }
  };
like image 144
Kerrek SB Avatar answered Sep 18 '26 14:09

Kerrek SB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!