STL Vectors

The boidSpecies class makes use of the STL vector template.

STL is the Standard Template Library for C++.
Templates are a way of doing "generic programming", or of defining generic classes that can use other, arbitrary classes in their implementation. i.e., we can define a function in a template that is a series of instructions to apply to some object, without knowing what exact class that object will be (as long as, when we actually use the template, the object's class provides whatever functions the template expects).

The vector template is a form of generic array of objects of a particular class.
For example,

    vector<int> X;

declares X to be a vector of integers; this will be similar to an array of integers (int X[100]), but with a few more advanced features.

The most important feature of the vector template, for our purposes, is that it has no size limit - we can add as many objects to the array as we like, and it will automatically resize itself any time it runs out of space.

To add a new element to the end of a vector, use the push_back() function. To find out the number of items currently in a vector, use the size() function.

So, in boidSpecies we keep a list of all the boids of a particular species by declaring:

    vector<boid *> members_;

and adding new ones to the list via:

    void boidSpecies::add(boid *b)
        {
        members_.push_back(b);
        }

The neighbors() function returns a list of nearby boids of the same species, for a given boid. In this implementation, the neighbors list is created dynamically, by:

    vector<boid *> * list = new vector<boid *>;