• Advertisement
Sign in to follow this  

c++ : a container with many rulesets

This topic is 3389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

c++ I'm looking for a specific type of templated container; it would have more than one ordered set; for each of these, it would have a custom sorting predicate and a custom insertion predicate. It would also have a default set of all objects that are in the container with the automatic predicate of that container. The reason I need this is that I've encountered situations where you have to choose between one of several ways to sort a list of objects; I'm a big advocate of taking both choices when there appears to be a dilemma. Many dilemmas are false dilemmas in that you don't need to choose only one. I have 3 instances of this problem in my game; Firstly, a list of objects; some are active and some are not. on one hand I want a list of all these objects, but I also need a separate list for each case. secondly, a list of renderable nodes; transparent ones go into one list and are ordered by distance from the camera, and opaque ones go into another and are ordered by material. thirdly, entities in the world; some bits of the engine want a flat list of all entities by their abstract base type, and some like a list of only a specific type of entity. There seems to be a trade-off in entity interfaces between these two, and as usual I suspect it would be faster to have both. So you can see why I want to find this container. Obviously, you sacrifice insertion time. However, you either break even or gain with lookup times; you can either lookup an element from every element in the container, in which case it delegates to the list of every element. Or, you can lookup from the specific lists, in which case, it again delegates, directly to one of the specific lists. The implementation details of this storage type are fuzzy. I'm not sure what the best container would be, although I suspect multiset; it supports sorting of elements, and you could easily get the equivalent of a map or multimap using pair<key,value> as the element type, and use a sorting predicate that only considers the key.

Share this post


Link to post
Share on other sites
Advertisement
Maybe boost multi-index container suits your need? http://www.boost.org/doc/libs/1_37_0/libs/multi_index/doc/index.html

I have never used them myself so I am not sure that container meets your needs completely.

Share this post


Link to post
Share on other sites
Why do you need one container for this? The clean, simple answer is to just have multiple containers that are sorted/managed independently. If you want to merge the two lists into a single container, how do you define a strict ordering between the two different types of node? How do you ensure that you will traverse the list in the correct order to handle both jobs related to the contained data?

Share this post


Link to post
Share on other sites
What you're looking for is Boost.MultiIndex.
As the name suggests, it's a collection of elements with various indexes attached to it. Kind of like a database.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement