[Bf-blender-cvs] [c2e80cfaa30] master: BLI: add index_range method to some data structures
Jacques Lucke
noreply at git.blender.org
Fri Feb 7 17:31:17 CET 2020
Commit: c2e80cfaa302e666421a8adee8d2b25a69d0700e
Author: Jacques Lucke
Date: Fri Feb 7 17:23:25 2020 +0100
Branches: master
https://developer.blender.org/rBc2e80cfaa302e666421a8adee8d2b25a69d0700e
BLI: add index_range method to some data structures
This can be used to iterate over all indices with less code.
===================================================================
M source/blender/blenlib/BLI_allocator.h
M source/blender/blenlib/BLI_array_cxx.h
M source/blender/blenlib/BLI_array_ref.h
M source/blender/blenlib/BLI_vector.h
===================================================================
diff --git a/source/blender/blenlib/BLI_allocator.h b/source/blender/blenlib/BLI_allocator.h
index 52fa8d2b705..82cf76e425c 100644
--- a/source/blender/blenlib/BLI_allocator.h
+++ b/source/blender/blenlib/BLI_allocator.h
@@ -30,6 +30,7 @@
*/
#include <stdlib.h>
+#include <algorithm>
#include "MEM_guardedalloc.h"
diff --git a/source/blender/blenlib/BLI_array_cxx.h b/source/blender/blenlib/BLI_array_cxx.h
index c7704e20fb1..e987121d68c 100644
--- a/source/blender/blenlib/BLI_array_cxx.h
+++ b/source/blender/blenlib/BLI_array_cxx.h
@@ -27,6 +27,7 @@
#include "BLI_allocator.h"
#include "BLI_array_ref.h"
#include "BLI_memory_utils_cxx.h"
+#include "BLI_index_range.h"
namespace BLI {
@@ -182,6 +183,11 @@ template<typename T, typename Allocator = GuardedAllocator> class Array {
return m_data + m_size;
}
+ IndexRange index_range() const
+ {
+ return IndexRange(m_size);
+ }
+
private:
T *allocate(uint size)
{
diff --git a/source/blender/blenlib/BLI_array_ref.h b/source/blender/blenlib/BLI_array_ref.h
index e34647676d8..bef7b862bf9 100644
--- a/source/blender/blenlib/BLI_array_ref.h
+++ b/source/blender/blenlib/BLI_array_ref.h
@@ -246,6 +246,11 @@ template<typename T> class ArrayRef {
return fallback;
}
+ IndexRange index_range() const
+ {
+ return IndexRange(m_size);
+ }
+
/**
* Get a new array ref to the same underlying memory buffer. No conversions are done.
* Asserts when the sizes of the types don't match.
@@ -411,6 +416,11 @@ template<typename T> class MutableArrayRef {
{
return ArrayRef<T>(m_start, m_size);
}
+
+ IndexRange index_range() const
+ {
+ return IndexRange(m_size);
+ }
};
/**
diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h
index 46c46a1440f..5c03a896692 100644
--- a/source/blender/blenlib/BLI_vector.h
+++ b/source/blender/blenlib/BLI_vector.h
@@ -37,6 +37,7 @@
#include "BLI_listbase_wrapper.h"
#include "BLI_math_base.h"
#include "BLI_allocator.h"
+#include "BLI_index_range.h"
#include "MEM_guardedalloc.h"
@@ -520,6 +521,11 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve
return (uint)(m_capacity_end - m_begin);
}
+ IndexRange index_range() const
+ {
+ return IndexRange(this->size());
+ }
+
void print_stats() const
{
std::cout << "Small Vector at " << (void *)this << ":" << std::endl;
More information about the Bf-blender-cvs
mailing list