summaryrefslogtreecommitdiffstats
path: root/mfbt/Range.h
diff options
context:
space:
mode:
Diffstat (limited to 'mfbt/Range.h')
-rw-r--r--mfbt/Range.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/mfbt/Range.h b/mfbt/Range.h
index 47d91bb0c..753fe07f8 100644
--- a/mfbt/Range.h
+++ b/mfbt/Range.h
@@ -9,6 +9,7 @@
#include "mozilla/RangedPtr.h"
#include "mozilla/TypeTraits.h"
+#include "mozilla/Span.h"
#include <stddef.h>
@@ -44,6 +45,19 @@ public:
mEnd(aOther.mEnd)
{}
+ MOZ_IMPLICIT Range(Span<T> aSpan)
+ : Range(aSpan.Elements(), aSpan.Length())
+ {
+ }
+
+ template<typename U,
+ class = typename EnableIf<IsConvertible<U (*)[], T (*)[]>::value,
+ int>::Type>
+ MOZ_IMPLICIT Range(const Span<U>& aSpan)
+ : Range(aSpan.Elements(), aSpan.Length())
+ {
+ }
+
RangedPtr<T> begin() const { return mStart; }
RangedPtr<T> end() const { return mEnd; }
size_t length() const { return mEnd - mStart; }
@@ -51,8 +65,26 @@ public:
T& operator[](size_t aOffset) const { return mStart[aOffset]; }
explicit operator bool() const { return mStart != nullptr; }
+
+ operator Span<T>() { return Span<T>(mStart.get(), length()); }
+
+ operator Span<const T>() const { return Span<T>(mStart.get(), length()); }
};
+template<class T>
+Span<T>
+MakeSpan(Range<T>& aRange)
+{
+ return aRange;
+}
+
+template<class T>
+Span<const T>
+MakeSpan(const Range<T>& aRange)
+{
+ return aRange;
+}
+
} // namespace mozilla
#endif /* mozilla_Range_h */