Bug 1546697 - EnumeratedArray should have a copy assignment operator. r=froydnj

I'll use this in a following patch.

Differential Revision: https://phabricator.services.mozilla.com/D28679

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-04-25 16:40:47 +00:00
Родитель 3e1e7ce302
Коммит c7aac206e4
2 изменённых файлов: 25 добавлений и 6 удалений

Просмотреть файл

@ -80,6 +80,13 @@ class EnumeratedArray {
return *this;
}
EnumeratedArray& operator=(const EnumeratedArray& aOther) {
for (size_t i = 0; i < kSize; i++) {
mArray[i] = aOther.mArray[i];
}
return *this;
}
typedef typename ArrayType::iterator iterator;
typedef typename ArrayType::const_iterator const_iterator;
typedef typename ArrayType::reverse_iterator reverse_iterator;

Просмотреть файл

@ -6,29 +6,41 @@
#include "mozilla/EnumeratedArray.h"
using mozilla::EnumeratedArray;
enum class AnimalSpecies { Cow, Sheep, Pig, Count };
using TestArray = EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int>;
void TestInitialValueByConstructor() {
using namespace mozilla;
// Style 1
EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount(1, 2, 3);
TestArray headCount(1, 2, 3);
MOZ_RELEASE_ASSERT(headCount[AnimalSpecies::Cow] == 1);
MOZ_RELEASE_ASSERT(headCount[AnimalSpecies::Sheep] == 2);
MOZ_RELEASE_ASSERT(headCount[AnimalSpecies::Pig] == 3);
// Style 2
EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount2{5, 6, 7};
TestArray headCount2{5, 6, 7};
MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Cow] == 5);
MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Sheep] == 6);
MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Pig] == 7);
// Style 3
EnumeratedArray<AnimalSpecies, AnimalSpecies::Count, int> headCount3(
{8, 9, 10});
TestArray headCount3({8, 9, 10});
MOZ_RELEASE_ASSERT(headCount3[AnimalSpecies::Cow] == 8);
MOZ_RELEASE_ASSERT(headCount3[AnimalSpecies::Sheep] == 9);
MOZ_RELEASE_ASSERT(headCount3[AnimalSpecies::Pig] == 10);
}
void TestAssignment() {
TestArray headCount{8, 9, 10};
TestArray headCount2;
headCount2 = headCount;
MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Cow] == 8);
MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Sheep] == 9);
MOZ_RELEASE_ASSERT(headCount2[AnimalSpecies::Pig] == 10);
}
int main() {
TestInitialValueByConstructor();
TestAssignment();
return 0;
}
}