diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_span.hh | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_span.hh b/source/blender/blenlib/BLI_span.hh index 67bb32304de..2d875fe73be 100644 --- a/source/blender/blenlib/BLI_span.hh +++ b/source/blender/blenlib/BLI_span.hh @@ -594,6 +594,21 @@ template<typename T> class MutableSpan { } /** + * Does a linear search to count how often the value is in the array. + * Returns the number of occurrences. + */ + int64_t count(const T &value) const + { + int64_t counter = 0; + for (const T &element : *this) { + if (element == value) { + counter++; + } + } + return counter; + } + + /** * Returns a new span to the same underlying memory buffer. No conversions are done. */ template<typename NewT> MutableSpan<NewT> cast() const |