/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Common iterator implementation for array classes e.g. nsTArray.
// We have implemented a custom iterator class for array rather than using // raw pointers into the backing storage to improve the safety of C++11-style // range based iteration in the presence of array mutation, or script execution // (bug 1299489). // // Mutating an array which is being iterated is still wrong, and will either // cause elements to be missed or firefox to crash, but will not trigger memory // safety problems due to the release-mode bounds checking found in ElementAt. // // Dereferencing this iterator returns type Element. When Element is a reference // type, this iterator implements the full standard random access iterator spec, // and can be treated in many ways as though it is a pointer. Otherwise, it is // just enough to be used in range-based for loop. template <class Element, class ArrayType> class ArrayIterator { public: typedef ArrayType array_type; typedef ArrayIterator<Element, ArrayType> iterator_type; typedeftypename array_type::index_type index_type; typedef std::remove_reference_t<Element> value_type; typedef ptrdiff_t difference_type; typedef value_type* pointer; typedef value_type& reference; typedef std::random_access_iterator_tag iterator_category; typedef ArrayIterator<detail::AddInnerConstT<Element>, ArrayType>
const_iterator_type;
// These operators depend on the release mode bounds checks in // ArrayIterator::ElementAt for safety.
value_type* operator->() const { returnconst_cast<value_type*>(&mArray->ElementAt(mIndex));
}
Element operator*() const { returnconst_cast<Element>(mArray->ElementAt(mIndex));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.