Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: vector <pair<vector<int>,int> >

This is what I am aiming to do...

vector < pair<vector<int>,int> > var_name (x, pair <vector<int>(y),int>);

Where x is the size of the vector var_name and y is the size of the vector inside the pair.

The above statement doesn't work because the pair template only allows constants. How can I go about getting both my vectors to size to x and y respectively?

like image 414
Jimmy Huch Avatar asked Dec 09 '25 02:12

Jimmy Huch


2 Answers

vector<pair<vector<int>,int> > var_name(x, make_pair(vector<int>(y), 0));
like image 200
Benjamin Lindley Avatar answered Dec 10 '25 16:12

Benjamin Lindley


Simplify it as:

pair<vector<int>,int> value(vector<int>(y), 0);
vector<pair<vector<int>,int> > var_name(x, value);

If you like your own syntax, then you should be doing this:

vector<pair<vector<int>,int> > var_name(x, std::make_pair(vector<int>(y), 0));
like image 20
Nawaz Avatar answered Dec 10 '25 16:12

Nawaz



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!