Reputation: 53
What I want to achieve is to initialize a pair of a vector with a certain length and a certain initialization number
I know that a vector can be initialized with the same elements:
std::vector v(length, number);
and a pair:
std::pair<int> p(number, number);
so combining those two together I thought of:
std::pair<std::vector<int>, std::vector<int>> pv((length, number),(length, number));
Unfortunately this doesn't work
Upvotes: 0
Views: 108
Reputation: 172894
You could use braces (list initialization) from C++11.
std::pair<std::vector<int>, std::vector<int>> pv({length, number}, {length, number});
Upvotes: 1
Reputation:
size_t length = 5;
int number = 0;
std::pair<std::vector<int>, std::vector<int>> pv(std::vector<int>(length, number), std::vector<int>(length, number));
Upvotes: 2