Category : swap

int main () { std::map<char,int> foo,bar; foo[‘x’]=100; foo[‘y’]=200; foo[‘z’]=300; bar[‘x’]=100; bar[‘y’]=2000; bar[‘zz’]=400; foo=bar; return 0; } Is it such a process that foo clear all it’s elements and then traverse bar to construct it’s new elements? Or foo traverse all the keys of foo and bar and then execute only necessary modification? I encountered such ..

Read more

I have a class C with multiple member variables and I’m programmig a binary heap whose elements are of the type std::unique_ptr. For the reordering of elements in the heap, I’m currently calling std::swap(x,y) where x and y are references to unique_ptr. I’m a bit confused with the explanation of this function on cplusplus.com and ..

Read more

I want to swap a global vector and a local vector, and my question is the local vector is on he stack.The swap operator will exchange two vector by pointer, so after swap, the global vector will point to the local vector, which is on stack. When leave the scope, the local vector will be ..

Read more