开发者

Why valarray does not have a swap function like vector in C++03? [closed]

开发者 https://www.devze.com 2023-03-23 20:39 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消