From: feedable <[email protected]>
gcc/ChangeLog:
* vec.h (array_slice::contains): New function.
(array_slice::find): New function.
---
gcc/vec.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/gcc/vec.h b/gcc/vec.h
index a2ff7a9b77694..9d25678029832 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -2422,6 +2422,15 @@ public:
const value_type &back () const;
const value_type &operator[] (unsigned int i) const;
+ /* Check if there is an element equal to V exists in the array. */
+ template<class U>
+ bool contains (const U &v);
+
+ /* Check if there is an element in the array that satisfies the predicate
+ PRED. */
+ template<class F>
+ bool find (const F &pred);
+
unsigned size () const { return m_size; }
size_t size_bytes () const { return m_size * sizeof (T); }
bool empty () const { return m_size == 0; }
@@ -2486,6 +2495,28 @@ array_slice<T>::operator[] (unsigned int i) const
return m_base[i];
}
+template<typename T>
+template<typename U>
+bool
+array_slice<T>::contains (const U &v)
+{
+ for (const auto &x : *this)
+ if (v == x)
+ return true;
+ return false;
+}
+
+template<typename T>
+template<typename F>
+bool
+array_slice<T>::find (const F &pred)
+{
+ for (const auto &x : *this)
+ if (pred (x))
+ return true;
+ return false;
+}
+
template<typename T>
array_slice<T>
make_array_slice (T *base, unsigned int size)
--
2.54.0