
----- Mensaje original ----- De: Janek Kozicki <janek_listy@wp.pl> Fecha: Miércoles, Noviembre 29, 2006 8:36 pm Asunto: Re: [boost] [ptr_container] and [multi_index] ? Para: boost@lists.boost.org [...]
Many thanks, it helps me a lot. The additional data structure maybe will be used later if the performace of D becomes more important. Already a constant time for A,B and C is a really good news.
You assured me that going multi_index is the way to go. Therefore I should work my way through using PtrContainer and MultiIndex together. I guess that it will result in a new kind of container (mosty due to fact that PtrContainer is so different from ''typical'' containers), probably PtrMultiIndex ?
To be honest, I don't think there's any sensible way to merge these two from the outside, i.e. without internal changes to the libraries. One critical problem is that both containers (as most other containers do) reclaim element ownership. A humble substitute for PtrContainer would be to store shared_ptr<Base>s in a multi_index_container. Note that B.MI predefined key extractors allow you to handle (smart) pointers with minimal hassle: typedef multi_index_container< boost::shared_ptr<Base>, indexed_by< // note the key extractor does not mention any shared_ptr; // const_mem_fun automatically dereferences the pointers // to get to the Base& needed ordered_unique<const_mem_fun<Base,int,&Base::get_x> >, ... Of course, you lose many advantages Boost.PtrContainer is designed to provide you with, for instance: * Null pointer handling overhead as compared to shared_ptr, * Indirected interface (http://tinyurl.com/y6t7ja ).
Accessing keys through pointers will require the base class of everything that is stored in the container to contain all the necessary keys.
Not necessarily so: you can resort to const_mem_fun<> to use a virtual function as the key provider: class Base { virtual int get_x()const = 0; ... };
Currently I'm working on something else, so I will not start right now. It waits in my 'queue' :) I guess that the real coding will happen not earlier than in one/two months from now. But in the meantimeif you have some useful thoughts about merging MutliIndex and PtrContainer they are welcome. Maybe with your guidance (the authors of those two libraries) we will make it.
Nevertheless, when I will start this task I'll let you know by asking more specific questions about merging those two.
Good luck with your projects, don't hesitate to come back here for further discussion. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo