View Full Version : Qvector
phillip_Qt
27th November 2007, 10:45
Hi ALL
can any body help me by telling what will bw the Qt equivalent of std::vector.swap().
Thank you all.
jpn
27th November 2007, 10:58
Take a look at QtAlgorithms.
phillip_Qt
27th November 2007, 11:30
Thanx. i went through the document. wat i found is qSwap() which can swap the tow passing element. but my requirment is replacement of std::vector.swap(vector element);
i ve stored some values. like
std::vector<int> vectelem;
int a;
int b;
vectelem.push_back(a);
vectelem.push_back(b);
swap(vectelem);
how to replace in Qt?
wysota
27th November 2007, 11:46
swap is not part of std::vector but is a separate algorithm. You can use it with QVector as well
QVector<int> v;
v.push_back(7);
v.push_back(8);
std::swap(v[0], v[1]);
By the way, I think your code is incorrect - you have to let swap() know which elements to swap. And you can use qSwap() as a replacement for swap().
Or maybe you wanted to use std::reverse()?
QVector<int> v;
v.push_back(7);
v.push_back(8);
std::reverse(v.begin(), v.end());
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.