Elements in the history are accessed with the operator[]. The current history value is stored in history[0]; the previous value is stored in history[-1], etc. The oldest history value is stored in history[-getSize()+1].
Values are placed into the history by using the insert() function. When insert() is called, the current value in history[0] moves to history[-1], and the current value in histroy[-1] moves to history[-2], etc.
// Creating a history called aHistory with 100 elements:
History<int> aHistory(100);
// Initialize the contents of aHistory:
aHistory.zero();
// insert values into the history:
for (int i=1; i<10; i++) {
aHistory.insert(i);
}
// the next line should print "aHistory[0] == 9":
cout << "aHistory[0] == " << aHistory[0] << endl;
// print out all the inserted elements:
// result should be: "9 8 7 6 5 4 3 2 1 0 0 0 "
for (i=0; i<12; i++) {
cout << aHistory[-i] << " ";
}
cout << endl;