Bug 1309466 - Add support for initializer_list to Array and EnumeratedArray.
authorJames Cheng <jacheng@mozilla.com>
Wed, 12 Oct 2016 15:08:47 +0800
changeset 868217 9a001e6d6775dc8c810cb9bf83a3bb9044354b4b
parent 865793 7ae377917236b7e6111146aa9fb4c073c0efc7f4
child 868218 d719a74f36f5f4f5d787666b2ec3894eadc7f110
push id149609
push userjacheng@mozilla.com
push dateFri, 14 Oct 2016 02:26:17 +0000
treeherdertry@d719a74f36f5 [default view] [failures only]
bugs1309466
milestone52.0a1
Bug 1309466 - Add support for initializer_list to Array and EnumeratedArray. MozReview-Commit-ID: 9sD9Rg4qsy1
mfbt/Array.h
mfbt/EnumeratedArray.h
--- a/mfbt/Array.h
+++ b/mfbt/Array.h
@@ -6,28 +6,37 @@
 
 /* A compile-time constant-length array with bounds-checking assertions. */
 
 #ifndef mozilla_Array_h
 #define mozilla_Array_h
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/InitializerList.h"
+#include "mozilla/Move.h"
 #include "mozilla/ReverseIterator.h"
 
 #include <stddef.h>
 
 namespace mozilla {
 
 template<typename T, size_t Length>
 class Array
 {
   T mArr[Length];
 
 public:
+  Array() = default;
+
+  template <typename... Args>
+  MOZ_IMPLICIT Array(Args&&... aArgs)
+    : mArr{mozilla::Forward<Args>(aArgs)...}
+  {}
+
   T& operator[](size_t aIndex)
   {
     MOZ_ASSERT(aIndex < Length);
     return mArr[aIndex];
   }
 
   const T& operator[](size_t aIndex) const
   {
--- a/mfbt/EnumeratedArray.h
+++ b/mfbt/EnumeratedArray.h
@@ -49,16 +49,21 @@ public:
 private:
   typedef Array<ValueType, kSize> ArrayType;
 
   ArrayType mArray;
 
 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++) {
       mArray[i] = aOther.mArray[i];
     }
   }
 
   EnumeratedArray(EnumeratedArray&& aOther)