Dynamic Array |
This is a general purpose
dynamic array, especially useful for numeric arrays because of operator
overloading. For instance, if A is a numeric array, then A++
will apply the ++ operator to all elements of A. Linked
list is used for allocating and releasing memory chunks.
Operations involving two arrays,
e.g. A+=B where both A and B are arrays,
will check for structure of equivalency. Two arrays are of same structure if
and only if the three structure members: Initial, Increment and size, coincide.
If a mismatch occurs, IncompatibleArraySizes exception is thrown.
For correctness of assignment
for types other than built-in, the assignment operator= must be
overloaded for the template type T.
Array supports all operations on type int. However, your template type T can support any subset that you desire. The compiler will only generate code for operators supported by T.
The following is an example using Array.
#include <ospace/advanced/Iterator.h>
#include <ospace/advanced/Array.h>
#include <ospace/std/iostream>
int main()
{
// Create two arrays, using default initial size of 32.
os_Array<int> First;
os_Array<int> Second;
// Put some values in the cells of First and Second array.
int i;
for (i = 0; i < First.Size(); i++)
{
First[i] = i + 5;
Second[i] = i + 7;
}
// Increment every cell of the Second array, then add them to
// corresponding corresponding cells of the first array.
First += Second++;
for (i = 0; i < First.Size(); i++)
{
cout << "First at index " << i << ' ' << First[i] << endl;
cout << "Second at index " << i << ' ' << Second[i] << endl;
}
// Make every cell of First the ratio of corresponding cells oond after setting all cells of Second to 3.
Second = 3;
First /= Second;
for (i = 0; i < First.Size(); i++)
cout << "First at index " << i << ' ' << First[i] << endl;
return 0;
}
Copyright©2005-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.