diff options
author | Jacques Lucke <jacques@blender.org> | 2022-06-29 13:06:47 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-06-29 13:07:02 +0300 |
commit | c51b8ec86364585c4088837c603b39752065bc34 (patch) | |
tree | 09ae73c3f19c8d726e769437f9073e74ef4696fe /source/blender/blenlib | |
parent | 43b65150ed3853e6f40b0236b548393eb029c123 (diff) |
BLI: add Vector.append_and_get_index with rvalue parameter
This makes it possible to use this method with `std::unique_ptr`.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_vector.hh | 10 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_vector_test.cc | 4 |
2 files changed, 12 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh index c23d846d277..1f5f97d754d 100644 --- a/source/blender/blenlib/BLI_vector.hh +++ b/source/blender/blenlib/BLI_vector.hh @@ -451,8 +451,16 @@ class Vector { */ int64_t append_and_get_index(const T &value) { + return this->append_and_get_index_as(value); + } + int64_t append_and_get_index(T &&value) + { + return this->append_and_get_index_as(std::move(value)); + } + template<typename... ForwardValue> int64_t append_and_get_index_as(ForwardValue &&...value) + { const int64_t index = this->size(); - this->append(value); + this->append_as(std::forward<ForwardValue>(value)...); return index; } diff --git a/source/blender/blenlib/tests/BLI_vector_test.cc b/source/blender/blenlib/tests/BLI_vector_test.cc index 29b6d2b41fe..3a12fe14de3 100644 --- a/source/blender/blenlib/tests/BLI_vector_test.cc +++ b/source/blender/blenlib/tests/BLI_vector_test.cc @@ -264,7 +264,8 @@ TEST(vector, AppendAndGetIndex) EXPECT_EQ(vec.append_and_get_index(10), 1); EXPECT_EQ(vec.append_and_get_index(10), 2); vec.append(10); - EXPECT_EQ(vec.append_and_get_index(10), 4); + int value = 10; + EXPECT_EQ(vec.append_and_get_index(value), 4); } TEST(vector, AppendNonDuplicates) @@ -479,6 +480,7 @@ TEST(vector, UniquePtrValue) vec.remove_and_reorder(0); vec.remove(0); EXPECT_EQ(vec.size(), 1); + EXPECT_EQ(vec.append_and_get_index(std::make_unique<int>(4)), 1); UNUSED_VARS(a, b); } |