An example might make it clearer. This is an implementation of the standard shuffle algorithm with templates:
Code:
template <typename T> void shuffle(T& t)
{
for(int i = t.size() - 1; i > 0; i--)
{
int j = rand() % i;
std::swap(t[i], t[j]);
}
}
That function alone will automatically work for any indexable container, with nearly any type of object inside the container (as long as it works with std::swap). You don't need to write separate versions for a plain array of ints, an std::vector of FooBar class objects, a Boost::multi_index set of booleans, etc.
Code:
std::vector<int> v(20);
// ... fill v with values...
shuffle(v);