G+Smo
24.08.0
Geometry + Simulation Modules
|
This class is derived from std::vector, and adds sort tracking.
There are two basic ways to use a sorted vector:
METHOD 1 Always maintain sort order by inserting with push_sorted() - the location of new items is determined before inserting; since the vector remains sorted, this doesn't take too long (although for large batch insertions METHOD 2 is definitely faster);
METHOD 2 Allow batch insertion without sorting with push_unsorted(); then provide an additional call to sort the vector; before searching for an item, the vector is always sorted if needed;
Of course you need to provide an operator()< for the type of object you're sorting, if it doesn't have one. Example:
NOTE: C++ doesn't let you use an operator()< for POINTERS. This breaks down when creating the template code, as you end up with a ref to a ref which is not allowed. So if you have a vector of pointers, here's what you have to do:
FOR NOW, with straight C++, create a less-than functor, then pass that in to the functor versions of the class methods below. Create a functor, aka function object, as follows:
Usage example:
Once C++0x is available, I need to update this class to use a function object wrapper, and allow the user to set it in the constructor, then always use it automatically. http:en.wikipedia.org/wiki/C%2B%2B0x#Polymorphic_wrappers_for_function_objects
Inherits vector< T, _A >.