[Bf-blender-cvs] [686452fb1bc] master: BLI: add Vector.append_as method
Jacques Lucke
noreply at git.blender.org
Sat Apr 17 19:09:33 CEST 2021
Commit: 686452fb1bcf9454df8d816443925746f6645ca0
Author: Jacques Lucke
Date: Sat Apr 17 19:01:02 2021 +0200
Branches: master
https://developer.blender.org/rB686452fb1bcf9454df8d816443925746f6645ca0
BLI: add Vector.append_as method
This method is similar to `std::vector::emblace_back` in that it constructs
the new object inplace in the vector, removing the need for a move.
The `_as` suffix is consistent with similar behavior in Map and Set data structures.
===================================================================
M source/blender/blenlib/BLI_vector.hh
===================================================================
diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh
index 328d623787b..b7ff488ff0f 100644
--- a/source/blender/blenlib/BLI_vector.hh
+++ b/source/blender/blenlib/BLI_vector.hh
@@ -437,13 +437,17 @@ class Vector {
*/
void append(const T &value)
{
- this->ensure_space_for_one();
- this->append_unchecked(value);
+ this->append_as(value);
}
void append(T &&value)
+ {
+ this->append_as(std::move(value));
+ }
+ /* This is similar to std::vector::emblace_back. */
+ template<typename... ForwardValue> void append_as(ForwardValue &&... value)
{
this->ensure_space_for_one();
- this->append_unchecked(std::move(value));
+ this->append_unchecked_as(std::forward<ForwardValue>(value)...);
}
/**
@@ -474,10 +478,18 @@ class Vector {
* behavior when not enough capacity has been reserved beforehand. Only use this in performance
* 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_);
- new (end_) T(std::forward<ForwardT>(value));
+ new (end_) T(std::forward<ForwardT>(value)...);
end_++;
UPDATE_VECTOR_SIZE(this);
}
More information about the Bf-blender-cvs
mailing list