In the code example for std::transform, there is an example with code like this:
std::vector<int> foo;
std::vector<int> bar;
//add some elements to foo
bar.resize(foo.size());
//store elements transformed from foo's in bar
And I was wondering whether
std::vector<int> bar;
bar.resize(foo.size());
was any different from
std::vector<int> bar(foo.size());
and if so, how?
No, there's no difference. At least not in the way you show it (with no insertions into foo between the definition of bar and the call to resize).
No difference, except that the latter is a tiny bit more efficient and concise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With