3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
3DCoat arrays

Use the coat::list<...> template if you need simple arrays. See the full descriprion of cList (same as coat::list) for the full description.
There are several examples of valid operations with arrays

coat::list<int> array; // declare array of int-s
array.Add(1); // add the single integer value 1
array1.Add(2, 10); // add 10 elements, each element is 2
array1.Insert(3, 5); // insert the value 5 at position 3
array1.RemoveAt(5, 2); // remove 2 elements at the position 5
int x[3] = { 7,8,9 };
array1.AddRange(x, 3); // add 3 elements from the regular array
array.AddRange(array1); // add the whole array
array.Reverse(); // reverse the order of elements
int pos_of_2 = array1.find(2); // returns the position of the value 2, returns -1 if not found
for (int x : array) { // the for-cycle. In this case you may not erase array elements within the loop
//... do something ...
}
for (int i = 0; i < array.Count(); i++) { // indexed for-loop, in this case you can remove elements within the cycle
if (array[i] == 5) { // we remove element if it is exual to 5
array.Remove(i--);
}
}
array.Clear(); // set zero count of elements
array = array1; // you can assign one array to another one
array.forEach(
[&](int x) {
// do something with each element
});
array1.Fill(7); // fill with the same value
comms::cList< X > list
the array template, see cList
Definition CoreAPI.h:58

Of course you can use any std containers like the std::vector<...>. But coat::list is more convenient and functionally rich. 3DCoat offers other types of arrays for more specific applications. This is StackArray for the fast array creation and access without the mandatory memory allocation and BigDynArray for the huge amount of elements when they can't be allocated into a single memory chunk. Look also the ValuesField for the rich toolset over the 2D float fields/images.