1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=78:
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_Range_h_
9 #define mozilla_Range_h_
11 #include "mozilla/NullPtr.h"
12 #include "mozilla/RangedPtr.h"
18 // Range<T> is a tuple containing a pointer and a length.
25 typedef void (Range::* ConvertibleToBool
)();
29 Range() : mStart(nullptr, 0), mEnd(nullptr, 0) {}
30 Range(T
* p
, size_t len
)
31 : mStart(p
, p
, p
+ len
),
32 mEnd(p
+ len
, p
, p
+ len
)
35 RangedPtr
<T
> start() const { return mStart
; }
36 RangedPtr
<T
> end() const { return mEnd
; }
37 size_t length() const { return mEnd
- mStart
; }
39 T
& operator[](size_t offset
) {
40 return mStart
[offset
];
43 operator ConvertibleToBool() const { return mStart
? &Range::nonNull
: 0; }
46 } // namespace mozilla
48 #endif // mozilla_Range_h_