diff --git a/example/array.usage.cpp b/example/array.usage.cpp index 8c93dc7..cf82625 100644 --- a/example/array.usage.cpp +++ b/example/array.usage.cpp @@ -4,7 +4,7 @@ using namespace std; int main() { - Array a (10); + Array a (10); for (int i = 0; i < 1000; ++i) a[i] = i; diff --git a/lib/array.h b/lib/array.h index 465e931..528c0ba 100644 --- a/lib/array.h +++ b/lib/array.h @@ -61,7 +61,7 @@ class Array { return slice[index_in_slice]; }; - + public: int length; @@ -136,6 +136,22 @@ class Array { }; + // Check, whether all of elements + // in array satisfy requirement + // fn - function, which returns + // true or false + // + bool every(bool (*fn)(T)) { + for (int i = 0; i < this->length; ++i) { + T item = this->get(i); + bool satisfies = fn(item); + if (!satisfies) return 0; + } + + return 1; + }; + + // Create string from elements of array // separated by specified separator //