c++ - Sorting vector of pointers -


i need sort collection of element. there specific advantage of sorting vector of element* i.e

std::vector<element*> vectref; 

to sorting vector of element.

std::vector<element> vect; 

assuming write comparator accordingly.

element struct show below:

struct element {     record *elm;              element(record *rec)     {         elm = new record();         //...copy rec     }     ~element()     {         delete elm;     } }; 

how expensive element's copy constructor? deep copy of contained record object? sorting vector<element> require many copies of element objects unless swap overloaded properly. i'm not sure rules whether sort must use swap , if must use user's overloaded version of swap; http://accu.org/index.php/journals/466 has information that. sorting vector<element*> copying pointers around, cheaper. c++0x changes this, assuming element has efficient move constructor , move assignment operator.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -