Add a RangedPtr constructor accepting an array as a shorthand for RangedPtr(arr, N). rs=luke
authorJeff Walden <jwalden@mit.edu>
Tue, 07 Jun 2011 13:25:36 -0700
changeset 70988 fd805dbc154c49345e21b37bb56447e43de6d61d
parent 70987 bb9e5496b0aca48c09052c1342e4c4351a8ede87
child 70989 8967b946dbf18aa0a1d5e607788c5b5a38b86ba7
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersluke
milestone7.0a1
Add a RangedPtr constructor accepting an array as a shorthand for RangedPtr(arr, N). rs=luke
mfbt/RangedPtr.h
--- a/mfbt/RangedPtr.h
+++ b/mfbt/RangedPtr.h
@@ -118,16 +118,27 @@ class RangedPtr
       , rangeStart(p), rangeEnd(p + length)
 #endif
     {
         MOZ_ASSERT(length <= size_t(-1) / sizeof(T));
         MOZ_ASSERT(uintptr_t(rangeStart) + length * sizeof(T) >= uintptr_t(rangeStart));
         checkSanity();
     }
 
+    /* Equivalent to RangedPtr(arr, arr, N). */
+    template<size_t N>
+    RangedPtr(T arr[N])
+      : ptr(arr)
+#ifdef DEBUG
+      , rangeStart(arr), rangeEnd(arr + N)
+#endif
+    {
+      checkSanity();
+    }
+
     T* get() const {
         return ptr;
     }
 
     /*
      * You can only assign one RangedPtr into another if the two pointers have
      * the same valid range:
      *