Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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?

like image 601
xis Avatar asked Jul 30 '11 20:07

xis


People also ask

Which function is used to swap two vectors?

The std::vector::swap() function is used to swap the entire contents of one vector with another vector of same type. If std::swap() function is used for swapping two vectors A and B, it will call specialized std::swap algorithm for std::vector which in turn calls A.


2 Answers

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).

like image 68
James McNellis Avatar answered Oct 21 '22 05:10

James McNellis


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.

like image 44
Ben Voigt Avatar answered Oct 21 '22 04:10

Ben Voigt