101 Allocator allocator_;
113 # define UPDATE_VECTOR_SIZE(ptr) \
114 (ptr)->debug_size_ = static_cast<int64_t>((ptr)->end_ - (ptr)->begin_)
116 # define UPDATE_VECTOR_SIZE(ptr) ((void)0)
123 template<
typename OtherT,
int64_t OtherInlineBufferCapacity,
typename OtherAllocator>
131 Vector(Allocator allocator = {}) noexcept : allocator_(allocator)
133 begin_ = inline_buffer_;
135 capacity_end_ = begin_ + InlineBufferCapacity;
160 this->
resize(size, value);
166 template<
typename U,
typename std::enable_if_t<std::is_convertible_v<U, T>> * =
nullptr>
171 uninitialized_convert_n<U, T>(values.
data(),
size, begin_);
181 template<
typename U,
typename std::enable_if_t<std::is_convertible_v<U, T>> * =
nullptr>
192 typename std::enable_if_t<std::is_convertible_v<U, T>> * =
nullptr>
197 template<
typename InputIt,
200 typename std::enable_if_t<!std::is_convertible_v<InputIt, int>> * =
nullptr>
201 Vector(InputIt first, InputIt
last, Allocator allocator = {})
204 for (InputIt current = first; current !=
last; ++current) {
235 template<
int64_t OtherInlineBufferCapacity>
245 template<
int64_t OtherInlineBufferCapacity>
247 std::is_nothrow_move_constructible_v<T>)
252 if (other.is_inline()) {
253 if (
size <= InlineBufferCapacity) {
256 end_ = begin_ +
size;
261 begin_ =
static_cast<T *
>(
262 allocator_.allocate(
sizeof(
T) *
static_cast<size_t>(
capacity),
alignof(
T),
AT));
265 end_ = begin_ +
size;
270 begin_ = other.begin_;
272 capacity_end_ = other.capacity_end_;
275 other.begin_ = other.inline_buffer_;
276 other.end_ = other.begin_;
277 other.capacity_end_ = other.begin_ + OtherInlineBufferCapacity;
285 if (!this->is_inline()) {
286 allocator_.deallocate(begin_);
308 return begin_[index];
315 return begin_[index];
328 template<
typename U,
typename std::enable_if_t<is_span_convertible_po
inter_v<T, U>> * =
nullptr>
334 template<
typename U,
typename std::enable_if_t<is_span_convertible_po
inter_v<T, U>> * =
nullptr>
357 if (min_capacity > this->
capacity()) {
358 this->realloc_to_at_least(min_capacity);
372 if (new_size > old_size) {
377 destruct_n(begin_ + new_size, old_size - new_size);
379 end_ = begin_ + new_size;
393 if (new_size > old_size) {
398 destruct_n(begin_ + new_size, old_size - new_size);
400 end_ = begin_ + new_size;
422 if (!this->is_inline()) {
423 allocator_.deallocate(begin_);
426 begin_ = inline_buffer_;
428 capacity_end_ = begin_ + InlineBufferCapacity;
440 this->ensure_space_for_one();
445 this->ensure_space_for_one();
480 new (end_)
T(std::forward<ForwardT>(value));
532 for (
const T &value :
array) {
554 template<
typename InputIt>
void extend(InputIt first, InputIt
last)
571 insert_index, std::make_move_iterator(&value), std::make_move_iterator(&value + 1));
577 template<
typename InputIt>
void insert(
const T *insert_position, InputIt first, InputIt
last)
579 const int64_t insert_index = insert_position - begin_;
589 const int64_t new_size = old_size + insert_amount;
590 const int64_t move_amount = old_size - insert_index;
593 for (
int64_t i = 0; i < move_amount; i++) {
594 const int64_t src_index = insert_index + move_amount - i - 1;
595 const int64_t dst_index = new_size - i - 1;
597 new (
static_cast<void *
>(begin_ + dst_index))
T(std::move(begin_[src_index]));
602 end_ = begin_ + src_index + 1;
606 begin_[src_index].~T();
614 destruct_n(begin_ + new_size - move_amount, move_amount);
615 end_ = begin_ + insert_index;
619 end_ = begin_ + new_size;
633 this->
insert(0, std::move(value));
639 template<
typename InputIt>
void prepend(InputIt first, InputIt
last)
676 return begin_ == end_;
700 T value = std::move(*(end_ - 1));
715 T *element_to_remove = begin_ + index;
716 if (element_to_remove < end_) {
717 *element_to_remove = std::move(*(end_ - 1));
746 for (
int64_t i = index; i < last_index; i++) {
747 begin_[i] = std::move(begin_[i + 1]);
749 begin_[last_index].~T();
766 const int64_t move_amount = old_size - start_index - amount;
767 for (
int64_t i = 0; i < move_amount; i++) {
768 begin_[start_index + i] = std::move(begin_[start_index + amount + i]);
781 for (
const T *current = begin_; current != end_; current++) {
782 if (*current == value) {
783 return static_cast<int64_t>(current - begin_);
853 return std::reverse_iterator<T *>(this->
end());
855 std::reverse_iterator<T *>
rend()
857 return std::reverse_iterator<T *>(this->
begin());
860 std::reverse_iterator<const T *>
rbegin()
const
862 return std::reverse_iterator<T *>(this->
end());
864 std::reverse_iterator<const T *>
rend()
const
866 return std::reverse_iterator<T *>(this->
begin());
875 return static_cast<int64_t>(capacity_end_ - begin_);
907 std::cout <<
"Vector Stats: " << name <<
"\n";
908 std::cout <<
" Address: " <<
this <<
"\n";
909 std::cout <<
" Elements: " << this->
size() <<
"\n";
910 std::cout <<
" Capacity: " << (capacity_end_ - begin_) <<
"\n";
911 std::cout <<
" Inline Capacity: " << InlineBufferCapacity <<
"\n";
913 char memory_size_str[15];
915 std::cout <<
" Size on Stack: " << memory_size_str <<
"\n";
919 bool is_inline()
const
921 return begin_ == inline_buffer_;
924 void ensure_space_for_one()
926 if (
UNLIKELY(end_ >= capacity_end_)) {
927 this->realloc_to_at_least(this->
size() + 1);
933 if (this->
capacity() >= min_capacity) {
944 T *new_array =
static_cast<T *
>(
945 allocator_.allocate(
static_cast<size_t>(new_capacity) *
sizeof(
T),
alignof(
T),
AT));
950 allocator_.deallocate(new_array);
954 if (!this->is_inline()) {
955 allocator_.deallocate(begin_);
959 end_ = begin_ +
size;
960 capacity_end_ = begin_ + new_capacity;
964 #undef UPDATE_VECTOR_SIZE
970 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, const bool base_10) ATTR_NONNULL()
#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)
bool contains(const T &value) const
void append_unchecked(ForwardT &&value)
void append(const T &value)
void insert(const int64_t insert_index, const T &value)
friend bool operator==(const Vector &a, const Vector &b)
Vector(ListBase &values, Allocator allocator={})
Vector(InputIt first, InputIt last, Allocator allocator={})
void remove(const int64_t index)
Span< T > as_span() const
void resize(const int64_t new_size, const T &value)
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
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 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 prepend(const T &&value)
void extend_non_duplicates(Span< T > array)
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 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)
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)
ccl_device_inline float distance(const float2 &a, const float2 &b)