[Bf-blender-cvs] [0db9e85a7a3] functions: replace Vector.index with Vector.index_try
Jacques Lucke
noreply at git.blender.org
Sat Jan 18 20:18:12 CET 2020
Commit: 0db9e85a7a3f25ff10c7aa28adb8f54d1c2eef9a
Author: Jacques Lucke
Date: Sat Jan 18 20:10:53 2020 +0100
Branches: functions
https://developer.blender.org/rB0db9e85a7a3f25ff10c7aa28adb8f54d1c2eef9a
replace Vector.index with Vector.index_try
===================================================================
M source/blender/blenlib/BLI_vector.h
===================================================================
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h
index a24c2a9fc8c..9fd7169868b 100644
--- a/source/blender/blenlib/BLI_vector.h
+++ b/source/blender/blenlib/BLI_vector.h
@@ -476,8 +476,7 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
void remove_first_occurrence_and_reorder(const T &value)
{
- int index = this->index(value);
- BLI_assert(index >= 0);
+ uint index = this->index(value);
this->remove_and_reorder((uint)index);
}
@@ -485,7 +484,7 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
* Do a linear search to find the value in the vector.
* When found, return the first index, otherwise return -1.
*/
- int index(const T &value) const
+ int index_try(const T &value) const
{
for (T *current = m_begin; current != m_end; current++) {
if (*current == value) {
@@ -495,13 +494,24 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
return -1;
}
+ /**
+ * Do a linear search to find the value in the vector.
+ * When found, return the first index, otherwise fail.
+ */
+ uint index(const T &value) const
+ {
+ int index = this->index_try(value);
+ BLI_assert(index >= 0);
+ return (uint)index;
+ }
+
/**
* Do a linear search to see of the value is in the vector.
* Return true when it exists, otherwise false.
*/
bool contains(const T &value) const
{
- return this->index(value) != -1;
+ return this->index_try(value) != -1;
}
/**
More information about the Bf-blender-cvs
mailing list