Bumping manifests a=b2g-bump
[gecko.git] / mfbt / Range.h
blob814a2821ad666eb1475e5ec65b3dae94aaf06c97
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/NullPtr.h"
11 #include "mozilla/RangedPtr.h"
13 #include <stddef.h>
15 namespace mozilla {
17 // Range<T> is a tuple containing a pointer and a length.
18 template <typename T>
19 class Range
21 const RangedPtr<T> mStart;
22 const RangedPtr<T> mEnd;
24 typedef void (Range::* ConvertibleToBool)();
25 void nonNull() {}
27 public:
28 Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {}
29 Range(T* aPtr, size_t aLength)
30 : mStart(aPtr, aPtr, aPtr + aLength),
31 mEnd(aPtr + aLength, aPtr, aPtr + aLength)
34 RangedPtr<T> start() const { return mStart; }
35 RangedPtr<T> end() const { return mEnd; }
36 size_t length() const { return mEnd - mStart; }
38 T& operator[](size_t aOffset) const { return mStart[aOffset]; }
40 operator ConvertibleToBool() const { return mStart ? &Range::nonNull : 0; }
43 } // namespace mozilla
45 #endif /* mozilla_Range_h */