99 # define UPDATE_VECTOR_SIZE(ptr) \
100 (ptr)->debug_size_ = static_cast<int64_t>((ptr)->end_ - (ptr)->begin_)
102 # define UPDATE_VECTOR_SIZE(ptr) ((void)0)
109 template<
typename OtherT,
int64_t OtherInlineBufferCapacity,
typename OtherAllocator>
117 Vector(Allocator allocator = {}) noexcept : allocator_(allocator)
119 begin_ = inline_buffer_;
121 capacity_end_ = begin_ + InlineBufferCapacity;
146 this->
resize(size, value);
152 template<
typename U, BLI_ENABLE_IF((std::is_convertible_v<U, T>))>
157 uninitialized_convert_n<U, T>(values.
data(),
size, begin_);
167 template<
typename U, BLI_ENABLE_IF((std::is_convertible_v<U, T>))>
176 template<
typename U,
size_t N, BLI_ENABLE_IF((std::is_convertible_v<U, T>))>
181 template<
typename InputIt,
188 for (InputIt current =
first; current !=
last; ++current) {
220 template<
int64_t OtherInlineBufferCapacity>
230 template<
int64_t OtherInlineBufferCapacity>
232 std::is_nothrow_move_constructible_v<T>)
237 if (other.is_inline()) {
238 if (
size <= InlineBufferCapacity) {
241 end_ = begin_ +
size;
246 begin_ =
static_cast<T *
>(
247 allocator_.allocate(
sizeof(
T) *
static_cast<size_t>(
capacity),
alignof(
T),
AT));
250 end_ = begin_ +
size;
255 begin_ = other.begin_;
257 capacity_end_ = other.capacity_end_;
260 other.begin_ = other.inline_buffer_;
261 other.end_ = other.begin_;
262 other.capacity_end_ = other.begin_ + OtherInlineBufferCapacity;
270 if (!this->is_inline()) {
271 allocator_.deallocate(begin_);
293 return begin_[index];
300 return begin_[index];
313 template<
typename U, BLI_ENABLE_IF((is_span_convertible_po
inter_v<T, U>))>
319 template<
typename U, BLI_ENABLE_IF((is_span_convertible_po
inter_v<T, U>))>
342 if (min_capacity > this->
capacity()) {
343 this->realloc_to_at_least(min_capacity);
357 if (new_size > old_size) {
362 destruct_n(begin_ + new_size, old_size - new_size);
364 end_ = begin_ + new_size;
378 if (new_size > old_size) {
383 destruct_n(begin_ + new_size, old_size - new_size);
385 end_ = begin_ + new_size;
417 if (!this->is_inline()) {
418 allocator_.deallocate(begin_);
421 begin_ = inline_buffer_;
423 capacity_end_ = begin_ + InlineBufferCapacity;
442 template<
typename... ForwardValue>
void append_as(ForwardValue &&...value)
444 this->ensure_space_for_one();
463 this->
append_as(std::forward<ForwardValue>(value)...);
495 new (end_)
T(std::forward<ForwardT>(value)...);
547 for (
const T &value :
array) {
586 insert_index, std::make_move_iterator(&value), std::make_move_iterator(&value + 1));
592 template<
typename InputIt>
void insert(
const T *insert_position, InputIt
first, InputIt
last)
594 const int64_t insert_index = insert_position - begin_;
604 const int64_t new_size = old_size + insert_amount;
605 const int64_t move_amount = old_size - insert_index;
608 for (
int64_t i = 0; i < move_amount; i++) {
609 const int64_t src_index = insert_index + move_amount - i - 1;
610 const int64_t dst_index = new_size - i - 1;
612 new (
static_cast<void *
>(begin_ + dst_index))
T(std::move(begin_[src_index]));
617 end_ = begin_ + src_index + 1;
621 begin_[src_index].~T();
629 destruct_n(begin_ + new_size - move_amount, move_amount);
630 end_ = begin_ + insert_index;
634 end_ = begin_ + new_size;
648 this->
insert(0, std::move(value));
667 return *(end_ - 1 - n);
673 return *(end_ - 1 - n);
708 return begin_ == end_;
732 T value = std::move(*(end_ - 1));
747 T *element_to_remove = begin_ + index;
748 T *last_element = end_ - 1;
749 if (element_to_remove < last_element) {
750 *element_to_remove = std::move(*last_element);
779 for (
int64_t i = index; i < last_index; i++) {
780 begin_[i] = std::move(begin_[i + 1]);
782 begin_[last_index].~T();
799 const int64_t move_amount = old_size - start_index - amount;
800 for (
int64_t i = 0; i < move_amount; i++) {
801 begin_[start_index + i] = std::move(begin_[start_index + amount + i]);
814 for (
const T *current = begin_; current != end_; current++) {
815 if (*current == value) {
816 return static_cast<int64_t>(current - begin_);
886 return std::reverse_iterator<T *>(this->
end());
888 std::reverse_iterator<T *>
rend()
890 return std::reverse_iterator<T *>(this->
begin());
893 std::reverse_iterator<const T *>
rbegin()
const
895 return std::reverse_iterator<T *>(this->
end());
897 std::reverse_iterator<const T *>
rend()
const
899 return std::reverse_iterator<T *>(this->
begin());
908 return static_cast<int64_t>(capacity_end_ - begin_);
927 return a.as_span() ==
b.as_span();
940 std::cout <<
"Vector Stats: " << name <<
"\n";
941 std::cout <<
" Address: " <<
this <<
"\n";
942 std::cout <<
" Elements: " << this->
size() <<
"\n";
943 std::cout <<
" Capacity: " << (capacity_end_ - begin_) <<
"\n";
944 std::cout <<
" Inline Capacity: " << InlineBufferCapacity <<
"\n";
946 char memory_size_str[15];
948 std::cout <<
" Size on Stack: " << memory_size_str <<
"\n";
952 bool is_inline()
const
954 return begin_ == inline_buffer_;
957 void ensure_space_for_one()
959 if (
UNLIKELY(end_ >= capacity_end_)) {
960 this->realloc_to_at_least(this->
size() + 1);
966 if (this->
capacity() >= min_capacity) {
977 T *new_array =
static_cast<T *
>(
978 allocator_.allocate(
static_cast<size_t>(new_capacity) *
sizeof(
T),
alignof(
T),
AT));
983 allocator_.deallocate(new_array);
987 if (!this->is_inline()) {
988 allocator_.deallocate(begin_);
992 end_ = begin_ +
size;
993 capacity_end_ = begin_ + new_capacity;
997 #undef UPDATE_VECTOR_SIZE
1003 template<
typename T,
int64_t InlineBufferCapacity = default_inline_buffer_capacity(sizeof(T))>
#define LISTBASE_FOREACH(type, var, list)
void BLI_str_format_byte_unit(char dst[15], long long int bytes, bool base_10) ATTR_NONNULL()
#define BLI_ENABLE_IF(condition)
#define BLI_NO_UNIQUE_ADDRESS
#define UPDATE_VECTOR_SIZE(ptr)
Read Guarded memory(de)allocation.
constexpr const T * data() const
constexpr int64_t size() const
T & operator[](int64_t index)
void insert(const int64_t insert_index, T &&value)
std::reverse_iterator< T * > rbegin()
void remove_and_reorder(const int64_t index)
Vector(const Vector< T, OtherInlineBufferCapacity, Allocator > &other)
MutableSpan< T > as_mutable_span()
Vector(const Vector &other)
Vector(Allocator allocator={}) noexcept
int64_t append_and_get_index(const T &value)
void prepend(const T &value)
bool contains(const T &value) const
void append(const T &value)
void insert(const int64_t insert_index, const T &value)
const T & last(const int64_t n=0) const
friend bool operator==(const Vector &a, const Vector &b)
T & last(const int64_t n=0)
Vector(InputIt first, InputIt last, Allocator allocator={})
void append_unchecked_as(ForwardT &&...value)
void remove(const int64_t index)
Span< T > as_span() const
void resize(const int64_t new_size, const T &value)
Vector(const ListBase &values, Allocator allocator={})
const T & operator[](int64_t index) const
void remove_first_occurrence_and_reorder(const T &value)
void print_stats(StringRef name="") const
std::reverse_iterator< const T * > rbegin() const
IndexRange index_range() const
int64_t append_and_get_index_as(ForwardValue &&...value)
void prepend(InputIt first, InputIt last)
void resize(const int64_t new_size)
int64_t first_index_of(const T &value) const
void clear_and_make_inline()
void extend_unchecked(Span< T > array)
void append_unchecked(const T &value)
void prepend(Span< T > values)
Vector(NoExceptConstructor, Allocator allocator={}) noexcept
Vector(Span< U > values, Allocator allocator={})
std::reverse_iterator< T * > rend()
void reserve(const int64_t min_capacity)
const T & const_reference
void remove(const int64_t start_index, const int64_t amount)
void extend(Span< T > array)
void insert(const T *insert_position, InputIt first, InputIt last)
void append_unchecked(T &&value)
void extend_non_duplicates(Span< T > array)
void reinitialize(const int64_t new_size)
Vector(int64_t size, const T &value, Allocator allocator={})
void append_non_duplicates(const T &value)
void fill(const T &value) const
void insert(const int64_t insert_index, InputIt first, InputIt last)
Vector(const std::array< U, N > &values)
Vector(int64_t size, Allocator allocator={})
void insert(const int64_t insert_index, Span< T > array)
void append_as(ForwardValue &&...value)
int64_t append_and_get_index(T &&value)
void extend(InputIt first, InputIt last)
void extend(const T *start, int64_t amount)
Vector & operator=(Vector &&other)
Vector(const std::initializer_list< U > &values)
friend bool operator!=(const Vector &a, const Vector &b)
void extend_unchecked(const T *start, int64_t amount)
void increase_size_by_unchecked(const int64_t n) noexcept
std::reverse_iterator< const T * > rend() const
Vector & operator=(const Vector &other)
int64_t first_index_of_try(const T &value) const
void append_n_times(const T &value, const int64_t n)
Vector(Vector< T, OtherInlineBufferCapacity, Allocator > &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
Vector(const std::initializer_list< T > &values)
T distance(const T &a, const T &b)
Container & move_assign_container(Container &dst, Container &&src) noexcept(std::is_nothrow_move_constructible_v< Container >)
void default_construct_n(T *ptr, int64_t n)
Container & copy_assign_container(Container &dst, const Container &src)
void initialized_fill_n(T *dst, int64_t n, const T &value)
constexpr int64_t default_inline_buffer_capacity(size_t element_size)
void uninitialized_fill_n(T *dst, int64_t n, const T &value)
void uninitialized_relocate_n(T *src, int64_t n, T *dst)
void destruct_n(T *ptr, int64_t n)
void uninitialized_copy_n(const T *src, int64_t n, T *dst)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)