diff options
Diffstat (limited to 'cpp/src/qpid/sys/CopyOnWriteArray.h')
-rw-r--r-- | cpp/src/qpid/sys/CopyOnWriteArray.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cpp/src/qpid/sys/CopyOnWriteArray.h b/cpp/src/qpid/sys/CopyOnWriteArray.h index e4ae3a6094..45a231dfd8 100644 --- a/cpp/src/qpid/sys/CopyOnWriteArray.h +++ b/cpp/src/qpid/sys/CopyOnWriteArray.h @@ -103,6 +103,24 @@ public: return false; } + template <class TestFn, class ModifierFn> + bool modify_if(TestFn f, ModifierFn & m) + { + if (!array) + return false; + { + Mutex::ScopedLock l(lock); + if (std::find_if(array->begin(), array->end(), f) != array->end()) + { + ArrayPtr copy(new std::vector<T>(*array)); + m(*std::find_if(copy->begin(), copy->end(), f)); + array = copy; + return true; + } + } + return false; + } + template <class F> F for_each(F f) { |