Why valarray does not have a swap function like vector in C++03? [closed]
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 开发者_StackOverflow中文版C++03?
Because it doesn't.
I doubt there is a much better answer than that. Omissions and mistakes happen (see also std::vector::resize
taking its second argument by value, the missing std::copy_if
algorithm, 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).
Because you didn't suggest it to the language committee.
As soon as you build your time machine, and deliver your request sufficiently far in advance of the standard's publication date for it to be included, C++03 will have it as well.
精彩评论