summaryrefslogtreecommitdiffstats
path: root/mfbt/Range.h
diff options
context:
space:
mode:
authortrav90 <travawine@palemoon.org>2018-10-06 17:29:50 -0500
committertrav90 <travawine@palemoon.org>2018-10-06 17:29:50 -0500
commitc2fa384d666aea1b119736f33116ac09e870fda0 (patch)
tree643a1009d32e68df792526c79db4a4921a7b02ec /mfbt/Range.h
parent323cb98de19b6f63b52d3fde5d7144712384c058 (diff)
downloadUXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar.gz
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar.lz
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar.xz
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.zip
Add mozilla::Span
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 */