On 09/09/2013 at 13:17, xxxxxxxx wrote:
Cinema 4D Version: 14
Platform: Mac ;
Language(s) : C++ ;
Hello, I recently switched over to sing R14 because of Jack's post about how much faster BaseArray was than GeDynamicArray. Anyway, I might be totally wrong, but I've been trying to use GetIndex() to find the location of elements in the array and it always returns not found. From what the SDK says and trying to figure it out myself, it looks like it can only find the location if I use the array entry in GetIndex(), otherwise it always returns -1.
c4d_misc::BaseArray<LONG> test; test.Append(0); test.Append(1); test.Append(2); test.Append(3); test.GetIndex(2); // returns -1 test.GetIndex(test); //so it's still looking for "2" and it correctly returns 2 this time
It seems like you could only use GetIndex() if you already knew what location of the element you're looking for. I'm sure I'm wrong but I can't find a way around it and would appreciate any help.
On 09/09/2013 at 13:45, xxxxxxxx wrote:
Read the description carefully:
Int GetIndex(const T & x) const [inline]
Gets the index of the element.
The element must be part of the array, otherwise (e.g. if x is a copy of an array element) InvalidArrayIndex will be returned.
index of element or InvalidArrayIndex (not element of this)
The function returns the index of the passed array element. If you just pass "2" to the function, it can't work. What should happen if multiple elements contain "2" ?
GetIndex comes in handy when you use an Iterator or AutoIterator.
On 09/09/2013 at 14:11, xxxxxxxx wrote:
Thanks Jack, that makes sense reading it again, I think I understand. I'm looking for a Find type function like in GeDynamicArray and I thought that was it. Is there such a thing in BaseArray? If not is there a way of going about it? Do I need to use a SortedArray?
Edit: A little late, nevermind I'm silly. You just use BaseSort to do it.