简体   繁体   中英

boost::ptr_vector sort function

i have a boost::ptr_vector that i want to keep maintained in sorted order.

i am creating a bunch of Customer objects containing several simple strings and values, which are then stored in a boost::ptr_vector, and they need to be ordered by one of the strings.

i have looked around but cant seem to find much information about the boost::ptr_vector member functions though, it appears that there is one called sort() which i think is relevant to what i am trying to do, however there is not much information on usage of this function.

is there an "insert in order" type function available to boost::ptr_vector? or do i need to load everything into the vector and then sort afterwards?

any help would be greatly appreciated thanks

You are asking too much of your ptr_vector . A ptr_vector is just a wrapper to std::vector . Likewise, there exist other wrappers to stdlib data structures.

A data structure that is always sorted (by performing sorted inserts) is the std::set . To use that functionality, you can use a boost::ptr_set . See here: http://www.boost.org/doc/libs/1_54_0/libs/ptr_container/doc/ptr_set.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM