Moin,
I can't find a funktion to swap 2 contents inside of a vector.
Isn't there an easy way to do that ?
Greetz
Greenhorn
Printable View
Moin,
I can't find a funktion to swap 2 contents inside of a vector.
Isn't there an easy way to do that ?
Greetz
Greenhorn
What's wrong with std::swap from <algorithm>?
The description says that it swaps from two different vectors, but not inside of one container ...
Does it although work ???
EDIT:
Ah, sorry, I'll try the std::swap function, but the exapmles are also using two different containers ...
Greetz
You might be looking at vector's own swap, which swaps two vectors. The generic swap algorithm, on the other hand, swaps any two objects of the same type (assuming that they can be swapped).Quote:
The description says that it swaps from two different vectors, but not inside of one container ...
For example, given a vector named vec with two elements, we could write:
Code:std::swap(vec[0], vec[1]);
It swaps two objects, whatever you want those objects to be. They can be integers, vectors, or whatever. I don't know where you're reading the description from, but it will swap anything.
Thanks, you both !!! I tried it and it works fine with std::swap.
@laserlight
That's exactly what I wanna do ;)
Now I can sleep well, tonight ...
Once again: Thank you laserlight and tabstop !
Greetz