Bug 1309466 - Enable Array and EnumeratedArray to be brace-initialized with initial contents. r=froydnj

MozReview-Commit-ID: 9sD9Rg4qsy1

--HG--
extra : rebase_source : bef928bca14e6d1a0a207359acfa56ecd93d605b
This commit is contained in:
James Cheng 2016-10-12 15:08:47 +08:00
parent 0819c4e347
commit 6178d3ca29
2 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/Move.h"
#include "mozilla/ReverseIterator.h"
#include <stddef.h>
@ -23,6 +24,16 @@ class Array
T mArr[Length];
public:
Array() {}
template <typename... Args>
MOZ_IMPLICIT Array(Args&&... aArgs)
: mArr{mozilla::Forward<Args>(aArgs)...}
{
static_assert(sizeof...(aArgs) == Length,
"The number of arguments should be equal to the template parameter Length");
}
T& operator[](size_t aIndex)
{
MOZ_ASSERT(aIndex < Length);

View File

@ -54,6 +54,11 @@ private:
public:
EnumeratedArray() {}
template <typename... Args>
MOZ_IMPLICIT EnumeratedArray(Args&&... aArgs)
: mArray{mozilla::Forward<Args>(aArgs)...}
{}
explicit EnumeratedArray(const EnumeratedArray& aOther)
{
for (size_t i = 0; i < kSize; i++) {