Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_vector.hh
| Show First 20 Lines • Show All 431 Lines • ▼ Show 20 Lines | public: | ||||
| /** | /** | ||||
| * Insert a new element at the end of the vector. | * Insert a new element at the end of the vector. | ||||
| * This might cause a reallocation with the capacity is exceeded. | * This might cause a reallocation with the capacity is exceeded. | ||||
| * | * | ||||
| * This is similar to std::vector::push_back. | * This is similar to std::vector::push_back. | ||||
| */ | */ | ||||
| void append(const T &value) | void append(const T &value) | ||||
| { | { | ||||
| this->ensure_space_for_one(); | this->append_as(value); | ||||
| this->append_unchecked(value); | |||||
| } | } | ||||
| void append(T &&value) | void append(T &&value) | ||||
| { | { | ||||
| this->append_as(std::move(value)); | |||||
| } | |||||
| /* This is similar to `std::vector::emplace_back`. */ | |||||
| template<typename... ForwardValue> void append_as(ForwardValue &&... value) | |||||
| { | |||||
| this->ensure_space_for_one(); | this->ensure_space_for_one(); | ||||
| this->append_unchecked(std::move(value)); | this->append_unchecked_as(std::forward<ForwardValue>(value)...); | ||||
| } | } | ||||
| /** | /** | ||||
| * Append the value to the vector and return the index that can be used to access the newly | * Append the value to the vector and return the index that can be used to access the newly | ||||
| * added value. | * added value. | ||||
| */ | */ | ||||
| int64_t append_and_get_index(const T &value) | int64_t append_and_get_index(const T &value) | ||||
| { | { | ||||
| Show All 14 Lines | void append_non_duplicates(const T &value) | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Append the value and assume that vector has enough memory reserved. This invokes undefined | * Append the value and assume that vector has enough memory reserved. This invokes undefined | ||||
| * behavior when not enough capacity has been reserved beforehand. Only use this in performance | * behavior when not enough capacity has been reserved beforehand. Only use this in performance | ||||
| * critical code. | * critical code. | ||||
| */ | */ | ||||
| template<typename ForwardT> void append_unchecked(ForwardT &&value) | void append_unchecked(const T &value) | ||||
| { | |||||
| this->append_unchecked_as(value); | |||||
| } | |||||
| void append_unchecked(T &&value) | |||||
| { | |||||
| this->append_unchecked_as(std::move(value)); | |||||
| } | |||||
| template<typename... ForwardT> void append_unchecked_as(ForwardT &&... value) | |||||
| { | { | ||||
| BLI_assert(end_ < capacity_end_); | BLI_assert(end_ < capacity_end_); | ||||
| new (end_) T(std::forward<ForwardT>(value)); | new (end_) T(std::forward<ForwardT>(value)...); | ||||
| end_++; | end_++; | ||||
| UPDATE_VECTOR_SIZE(this); | UPDATE_VECTOR_SIZE(this); | ||||
| } | } | ||||
| /** | /** | ||||
| * Insert the same element n times at the end of the vector. | * Insert the same element n times at the end of the vector. | ||||
| * This might result in a reallocation internally. | * This might result in a reallocation internally. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 485 Lines • Show Last 20 Lines | |||||