Bumping gaia.json for 7 gaia revision(s) a=gaia-bump
[gecko.git] / mfbt / Range.h
blob0ffaf3021b1b24ee446ec3abd671dd879ce16161
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_Range_h
8 #define mozilla_Range_h
10 #include "mozilla/RangedPtr.h"
12 #include <stddef.h>
14 namespace mozilla {
16 // Range<T> is a tuple containing a pointer and a length.
17 template <typename T>
18 class Range
20 const RangedPtr<T> mStart;
21 const RangedPtr<T> mEnd;
23 typedef void (Range::* ConvertibleToBool)();
24 void nonNull() {}
26 public:
27 Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {}
28 Range(T* aPtr, size_t aLength)
29 : mStart(aPtr, aPtr, aPtr + aLength),
30 mEnd(aPtr + aLength, aPtr, aPtr + aLength)
33 RangedPtr<T> start() const { return mStart; }
34 RangedPtr<T> end() const { return mEnd; }
35 size_t length() const { return mEnd - mStart; }
37 T& operator[](size_t aOffset) const { return mStart[aOffset]; }
39 operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; }
42 } // namespace mozilla
44 #endif /* mozilla_Range_h */