As title, I am confused about this. swap should be extremely useful if we are facing an iterative problem. The old vector and the new vector can be swapped by exchanging pointer-to-memory instead of contents. However, this is valid in std::vector but not in std::valarray. I am wondering why. In C++0x it seems the function is added, but why not in C++03?
As title, I am confused about this. swap should be extremely useful if we
Share
Because it doesn’t.
I doubt there is a much better answer than that. Omissions and mistakes happen (see also
std::vector::resizetaking its second argument by value, the missingstd::copy_ifalgorithm, and the very long list of closed Standard Library defects).It’s a good thing that the language continues to evolve and that mistakes like this can be rectified in future revisions of the language specification (like C++0x).