Handle self assignment for ObjArray.

This commit is contained in:
jief 2020-05-23 23:12:48 +03:00
parent be079edc92
commit a2b8d1217f
2 changed files with 14 additions and 0 deletions

View File

@ -187,6 +187,7 @@ const XObjArray<TYPE> &XObjArray<TYPE>::operator =(const XObjArray<TYPE> &anObjA
{
xsize ui;
if ( this == &anObjArray ) return *this; // self assignement
XObjArrayNC<TYPE>::Empty();
this->CheckSize(anObjArray.length(), 0);
for ( ui=0 ; ui<anObjArray.size() ; ui+=1 ) AddCopy(anObjArray.ElementAt(ui));

View File

@ -162,6 +162,19 @@ int XStringArray_tests()
array.Add(L"3333");
array.Add(L"4th_item");
XStringArray array2 = array;
if ( array2 != array ) return 22;
XStringArray* array2Ptr = &array2;
*array2Ptr = array2;
if ( array2 != array ) return 22;
}
{
XStringArray array;
array.Add(L"word1");
array.Add(L"other2");
array.Add(L"3333");
array.Add(L"4th_item");
array.remove("WOrd1"_XS8);
if ( !array.contains("word1"_XS8) ) return 22;
array.remove("word1"_XS8);