50template<
typename T,
typename Allocator>
struct VectorData {
112# define UPDATE_VECTOR_SIZE(ptr) (ptr)->debug_size_ = int64_t((ptr)->end_ - (ptr)->begin_)
114# define UPDATE_VECTOR_SIZE(ptr) ((void)0)
121 template<
typename OtherT,
int64_t OtherInlineBufferCapacity,
typename OtherAllocator>
125 static constexpr bool is_nothrow_move_constructible()
127 if constexpr (InlineBufferCapacity == 0) {
131 return std::is_nothrow_move_constructible_v<T>;
140 Vector(Allocator allocator = {})
noexcept : allocator_(allocator)
142 begin_ = inline_buffer_;
144 capacity_end_ = begin_ + InlineBufferCapacity;
167 this->
resize(size, value);
175 requires(std::is_convertible_v<U, T>)
186 requires(std::is_convertible_v<U, T>)
198 Vector(
const std::initializer_list<U> &values)
199 requires(std::is_convertible_v<U, T>)
206 template<
typename U,
size_t N>
208 requires(std::is_convertible_v<U, T>)
213 template<
typename InputIt>
217 requires(!std::is_convertible_v<InputIt, int>)
220 for (InputIt current =
first; current !=
last; ++current) {
235 template<
int64_t OtherInlineBufferCapacity>
245 template<
int64_t OtherInlineBufferCapacity>
247 is_nothrow_move_constructible())
250 if (other.is_inline()) {
251 const int64_t size = other.size();
254 constexpr bool other_is_same_type = std::is_same_v<Vector, std::decay_t<decltype(other)>>;
255 constexpr size_t max_full_copy_size = 32;
256 if constexpr (other_is_same_type && std::is_trivial_v<T> &&
257 sizeof(inline_buffer_) <= max_full_copy_size)
266 memcpy(inline_buffer_, other.inline_buffer_, sizeof(inline_buffer_));
267 this->increase_size_by_unchecked(size);
269 other.end_ = other.inline_buffer_;
275 if (OtherInlineBufferCapacity <= InlineBufferCapacity || size <= InlineBufferCapacity) {
277 uninitialized_relocate_n(other.begin_, size, begin_);
278 end_ = begin_ + size;
282 const int64_t capacity = size;
283 begin_ = static_cast<T *>(
284 allocator_.allocate(sizeof(T) * size_t(capacity), alignof(T), AT));
285 capacity_end_ = begin_ + capacity;
286 uninitialized_relocate_n(other.begin_, size, begin_);
287 end_ = begin_ + size;
290 other.end_ = other.inline_buffer_;
295 begin_ = other.begin_;
297 capacity_end_ = other.capacity_end_;
300 other.begin_ = other.inline_buffer_;
301 other.end_ = other.inline_buffer_;
302 other.capacity_end_ = other.inline_buffer_ + OtherInlineBufferCapacity;
321 if (
data.data !=
nullptr) {
325 capacity_end_ =
data.data +
data.capacity;
334 allocator_.deallocate(begin_);
356 return begin_[
index];
363 return begin_[
index];
407 if (min_capacity > this->
capacity()) {
408 this->realloc_to_at_least(min_capacity);
422 if (new_size > old_size) {
427 destruct_n(begin_ + new_size, old_size - new_size);
429 end_ = begin_ + new_size;
443 if (new_size > old_size) {
448 destruct_n(begin_ + new_size, old_size - new_size);
450 end_ = begin_ + new_size;
483 allocator_.deallocate(begin_);
486 begin_ = inline_buffer_;
488 capacity_end_ = begin_ + InlineBufferCapacity;
507 template<
typename... ForwardValue>
void append_as(ForwardValue &&...value)
509 this->ensure_space_for_one();
528 this->
append_as(std::forward<ForwardValue>(value)...);
560 new (end_)
T(std::forward<ForwardT>(value)...);
613 template<
int64_t OtherInlineBufferCapacity>
617 this->
extend(std::make_move_iterator(other.begin()), std::make_move_iterator(other.end()));
628 for (
const T &value :
array) {
667 insert_index, std::make_move_iterator(&value), std::make_move_iterator(&value + 1));
673 template<
typename InputIt>
void insert(
const T *insert_position, InputIt
first, InputIt
last)
675 const int64_t insert_index = insert_position - begin_;
685 const int64_t new_size = old_size + insert_amount;
686 const int64_t move_amount = old_size - insert_index;
689 for (
int64_t i = 0; i < move_amount; i++) {
690 const int64_t src_index = insert_index + move_amount - i - 1;
691 const int64_t dst_index = new_size - i - 1;
693 new (
static_cast<void *
>(begin_ + dst_index))
T(std::move(begin_[src_index]));
698 end_ = begin_ + src_index + 1;
702 begin_[src_index].~T();
706 if constexpr (std::is_rvalue_reference_v<
decltype(*first)>) {
707 std::uninitialized_move_n(
first, insert_amount, begin_ + insert_index);
710 std::uninitialized_copy_n(
first, insert_amount, begin_ + insert_index);
715 destruct_n(begin_ + new_size - move_amount, move_amount);
716 end_ = begin_ + insert_index;
720 end_ = begin_ + new_size;
734 this->
insert(0, std::move(value));
753 return *(end_ - 1 - n);
759 return *(end_ - 1 - n);
794 return begin_ == end_;
818 T value = std::move(*(end_ - 1));
833 T *element_to_remove = begin_ +
index;
834 T *last_element = end_ - 1;
835 if (element_to_remove < last_element) {
836 *element_to_remove = std::move(*last_element);
866 begin_[i] = std::move(begin_[i + 1]);
868 begin_[last_index].~T();
885 const int64_t move_amount = old_size - start_index - amount;
886 for (
int64_t i = 0; i < move_amount; i++) {
887 begin_[start_index + i] = std::move(begin_[start_index + amount + i]);
902 const T *prev_end = this->
end();
903 end_ = std::remove_if(this->
begin(), this->
end(), predicate);
906 return int64_t(prev_end - end_);
915 for (
const T *current = begin_; current != end_; current++) {
916 if (*current == value) {
917 return int64_t(current - begin_);
987 return std::reverse_iterator<T *>(this->
end());
989 std::reverse_iterator<T *>
rend()
991 return std::reverse_iterator<T *>(this->
begin());
994 std::reverse_iterator<const T *>
rbegin()
const
996 return std::reverse_iterator<const T *>(this->
end());
998 std::reverse_iterator<const T *>
rend()
const
1000 return std::reverse_iterator<const T *>(this->
begin());
1009 return int64_t(capacity_end_ - begin_);
1014 return end_ == capacity_end_;
1033 return this->
as_span().hash();
1038 return values.
hash();
1070 T *
data =
static_cast<T *
>(
1071 allocator_.allocate(
size_t(
size) *
sizeof(
T),
alignof(
T), __func__));
1076 allocator_.deallocate(
data);
1080 end_ = begin_ +
size;
1081 capacity_end_ = end_;
1086 data.size = end_ - begin_;
1087 data.capacity = capacity_end_ - begin_;
1088 data.allocator = allocator_;
1091 begin_ = inline_buffer_;
1093 capacity_end_ = begin_ + InlineBufferCapacity;
1105 name,
this, this->
size(), capacity_end_ - begin_, InlineBufferCapacity,
sizeof(*
this));
1110 return begin_ == inline_buffer_;
1114 void ensure_space_for_one()
1116 if (end_ >= capacity_end_) [[unlikely]] {
1117 this->realloc_to_at_least(this->size() + 1);
1123 if (this->
capacity() >= min_capacity) {
1131 const int64_t new_capacity = std::max(min_capacity, min_new_capacity);
1134 T *new_array =
static_cast<T *
>(
1135 allocator_.allocate(
size_t(new_capacity) *
sizeof(
T),
alignof(
T),
AT));
1140 allocator_.deallocate(new_array);
1144 if (!this->is_inline()) {
1145 allocator_.deallocate(begin_);
1149 end_ = begin_ +
size;
1150 capacity_end_ = begin_ + new_capacity;
1154#undef UPDATE_VECTOR_SIZE
1160template<
typename T,
int64_t InlineBufferCapacity = default_inline_buffer_capacity(sizeof(T))>
1164template<
typename T,
int64_t InlineBufferCapacity,
typename Allocator>
#define UPDATE_VECTOR_SIZE(ptr)
#define BLI_NO_UNIQUE_ADDRESS
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr const T * data() const
constexpr int64_t size() const
constexpr uint64_t hash() const
void insert(const int64_t insert_index, T &&value)
std::reverse_iterator< const T * > rbegin() const
std::reverse_iterator< T * > rbegin()
void remove_and_reorder(const int64_t index)
Vector(const Vector< T, OtherInlineBufferCapacity, Allocator > &other)
void print_stats(const char *name) const
int64_t remove_if(Predicate &&predicate)
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 SubdivCCGCoord &value) const
Vector & operator=(Vector &&other)
bool is_at_capacity() const
void append(const T &value)
void insert(const int64_t insert_index, const SubdivCCGCoord &value)
friend bool operator==(const Vector &a, const Vector &b)
const SubdivCCGCoord & last(const int64_t n=0) const
void append_unchecked_as(ForwardT &&...value)
void remove(const int64_t index)
void resize(const int64_t new_size, const T &value)
GuardedAllocator allocator_type
void remove_first_occurrence_and_reorder(const T &value)
IndexRange index_range() const
Vector(const std::initializer_list< U > &values)
int64_t append_and_get_index_as(ForwardValue &&...value)
Vector(InputIt first, InputIt last, Allocator allocator={})
void prepend(InputIt first, InputIt last)
Vector(const VectorData< T, Allocator > &data)
void resize(const int64_t new_size)
int64_t first_index_of(const SubdivCCGCoord &value) const
MutableSpan< T > as_mutable_span()
void extend_unchecked(Span< SubdivCCGCoord > array)
T & operator[](int64_t index)
void append_unchecked(const T &value)
void prepend(Span< T > values)
void extend(Vector< T, OtherInlineBufferCapacity, Allocator > &&other)
static uint64_t hash_as(const Span< T > values)
Vector(NoExceptConstructor, Allocator allocator={}) noexcept
const T & operator[](int64_t index) const
void reserve(const int64_t min_capacity)
const SubdivCCGCoord & const_reference
SubdivCCGCoord * iterator
std::reverse_iterator< T * > rend()
void remove(const int64_t start_index, const int64_t amount)
void extend(Span< T > array)
std::reverse_iterator< const T * > rend() const
void insert(const T *insert_position, InputIt first, InputIt last)
void append_unchecked(T &&value)
void extend_non_duplicates(Span< T > array)
Vector & operator=(const Vector &other)
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)
Span< T > as_span() const
Vector(int64_t size, Allocator allocator={})
const SubdivCCGCoord * const_pointer
Vector(Span< U > values, Allocator allocator={})
const SubdivCCGCoord & first() const
T & last(const int64_t n=0)
SubdivCCGCoord & reference
void insert(const int64_t insert_index, Span< T > array)
Vector(Vector< T, OtherInlineBufferCapacity, Allocator > &&other) noexcept(is_nothrow_move_constructible())
Vector(const std::array< U, N > &values)
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)
friend bool operator!=(const Vector &a, const Vector &b)
VectorData< T, Allocator > release()
void extend_unchecked(const T *start, int64_t amount)
void increase_size_by_unchecked(const int64_t n) noexcept
Vector(MutableSpan< U > values, Allocator allocator={})
SubdivCCGCoord value_type
int64_t first_index_of_try(const T &value) const
void append_n_times(const T &value, const int64_t n)
const SubdivCCGCoord * const_iterator
Vector(const std::initializer_list< T > &values)
void vector_print_stats(const char *name, const void *address, int64_t size, int64_t capacity, int64_t inlineCapacity, int64_t memorySize)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
void default_construct_n(T *ptr, int64_t n)
void initialized_fill_n(T *dst, int64_t n, const T &value)
Container & copy_assign_container(Container &dst, const Container &src)
Container & move_assign_container(Container &dst, Container &&src) noexcept(std::is_nothrow_move_constructible_v< Container >)
Vector< T, InlineBufferCapacity, RawAllocator > RawVector
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)
static constexpr bool is_Vector_v
void uninitialized_convert_n(const From *src, int64_t n, To *dst)
void destruct_n(T *ptr, int64_t n)
constexpr bool is_span_convertible_pointer_v
void uninitialized_copy_n(const T *src, int64_t n, T *dst)
BLI_NO_UNIQUE_ADDRESS Allocator allocator