From cb91fea97f84b513e30258e2b1f3743aac38898e Mon Sep 17 00:00:00 2001 From: jakcron Date: Thu, 13 Jul 2017 00:03:56 +1000 Subject: [PATCH] [fnd] Add hasElement() to List. --- lib/fnd/List.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/fnd/List.h b/lib/fnd/List.h index 9a23ed3..b71de0d 100644 --- a/lib/fnd/List.h +++ b/lib/fnd/List.h @@ -73,6 +73,27 @@ namespace fnd // functions void addElement(const T& element) { mElements.push_back(element); } + size_t getIndexOf(const T& element) const + { + for (size_t i = 0; i < getSize(); i++) + { + if (getElement(i) == element) return i; + } + + throw Exception("LIST", "Element does not exist"); + } + bool hasElement(const T& element) const + { + try + { + getIndexOf(element); + } catch (const Exception&) + { + return false; + } + + return true; + } size_t getSize() const { return mElements.size(); } void clear() { mElements.clear(); } private: