/* * Copyright 2020 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// A small std::vector-like type whose capacity is a compile-time constant. It // stores all data inline and never heap allocates (beyond what its element type // requires). Trying to grow it beyond its constant capacity is an error. // // TODO(bugs.webrtc.org/11391): Comparison operators. // TODO(bugs.webrtc.org/11391): Methods for adding and deleting elements. template <typename T, int fixed_capacity> class BoundedInlineVector {
static_assert(!std::is_const<T>::value, "T may not be const");
static_assert(fixed_capacity > 0, "Capacity must be strictly positive");
public: using size_type = int; using value_type = T; using const_iterator = const T*;
// Resizes the BoundedInlineVector to the given size, which must not exceed // its constant capacity. If the size is increased, the added elements are // default constructed. void resize(int new_size) {
RTC_DCHECK_GE(new_size, 0);
RTC_DCHECK_LE(new_size, fixed_capacity); if (new_size > storage_.size) {
bounded_inline_vector_impl::DefaultInitializeElements(
storage_.data + storage_.size, new_size - storage_.size);
} elseif (new_size < storage_.size) {
bounded_inline_vector_impl::DestroyElements(storage_.data + new_size,
storage_.size - new_size);
}
storage_.size = new_size;
}
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 und die Messung sind noch experimentell.