user3111311
user3111311

Reputation: 8011

Efficiently copying vectors in C++11?

Efficiently copying vectors in C++11?

Is it automatically done by the compiler when you say:

v1 = v2;

where v1 and v2 are std::vector.

Or should I use memcpy or else? I am talking about big vectors here, we have like 10000 elements in one.

Upvotes: 0

Views: 151

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385325

Yes, this is the most effective, correct and efficient method to copy a vector's contents into an existing vector.

All elements are copied fully and properly using the RAII idiom, and the allocation of backing memory should be as fast as possible since the new container size is known up-front.

Upvotes: 4

Related Questions