
Hello Daryle, Daryle Walker ha escrito:
I was thinking of using a multi-indexed container as part of an implementation of another container. The final container will have an interface like a set, but internally the elements sometimes have to be accessible via random-access iteration[1]. Implementing with a straight set would limit me to bidirectional iteration, which will slow down internal operations that need random access.
The internal multi-index container would have set and vector aspects, i.e. ordered-unique and random-access index specifiers. Even though the external interface will be like a set, should I have publicize the vector-like operations "capacity" and "reserve"? Will reserving capacity help in the ordered-unique part of any insertions?
Yes, reserving will gain you some performance even if insertions are made through the ordered_unique index --take into account that inserting through any index will also affect all other indices behind the scenes.
Alternatively, is there a better way to implement a set w/ random-access iteration besides this multi-index idea?
I hope there isn't :) Seriously, Boost.MultiIndex is designed to be as compact and efficient as possible, so it's probably an optimum choice for your problem with respect to memory usage and performance. As for the resulting user interface, it may not suit your particular needs, in which case you'll have to do some wrapping work over the core multi_index_container. Best, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo