michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* A compile-time constant-length array with bounds-checking assertions. */ michael@0: michael@0: #ifndef mozilla_Array_h michael@0: #define mozilla_Array_h michael@0: michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: michael@0: template michael@0: class Array michael@0: { michael@0: T arr[Length]; michael@0: michael@0: public: michael@0: T& operator[](size_t i) { michael@0: MOZ_ASSERT(i < Length); michael@0: return arr[i]; michael@0: } michael@0: michael@0: const T& operator[](size_t i) const { michael@0: MOZ_ASSERT(i < Length); michael@0: return arr[i]; michael@0: } michael@0: }; michael@0: michael@0: template michael@0: class Array michael@0: { michael@0: public: michael@0: T& operator[](size_t i) { michael@0: MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); michael@0: } michael@0: michael@0: const T& operator[](size_t i) const { michael@0: MOZ_ASSUME_UNREACHABLE("indexing into zero-length array"); michael@0: } michael@0: }; michael@0: michael@0: } /* namespace mozilla */ michael@0: michael@0: #endif /* mozilla_Array_h */