From 23c497886ebfbe95dbffa9320de4340d7a7445c9 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 11 Dec 2010 07:16:46 +0100 Subject: Added List::count(). --- common/list.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/list.h b/common/list.h index 2ad41fd..513f79c 100644 --- a/common/list.h +++ b/common/list.h @@ -22,10 +22,15 @@ class List : public B { } //! Check if specified item is present in list. - bool contains(T item) { + bool contains(const T& item) { return std::find(B::begin(), B::end(), item) != B::end(); } + //! Count number of instances of specified item in list. + std::size_t count(const T& item) { + return std::count(B::begin(), B::end(), item); + } + //! Delete item by index. void del(std::size_t index) { erase(B::begin() + index); -- cgit v1.2.3