From 55ae5202de17fb7f7d1d00fc76defa194d7f9b06 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 27 Nov 2010 02:43:27 +0100 Subject: Added List class to avoid reinventing features in each case. --- common/list.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 common/list.h (limited to 'common/list.h') diff --git a/common/list.h b/common/list.h new file mode 100644 index 0000000..92452f1 --- /dev/null +++ b/common/list.h @@ -0,0 +1,34 @@ +#ifndef LIST_H +#define LIST_H + +#include +#include +#include + +//! List class with extended functionality over std::vector. +template > +class List : public B { + public: + //! Sort the list. + void sort() { + std::sort(B::begin(), B::end()); + } + + //! Check if specified item is present in list. + bool contains(T item) { + return std::find(B::begin(), B::end(), item) != B::end(); + } + + //! Check whether list is empty or not. + operator bool() { + return !B::empty(); + } + + //! Allow serialization through Boost.Serialize. + template + void serialize(Archive & ar, const unsigned int version) { + ar & boost::serialization::base_object(*this); + } +}; + +#endif -- cgit v1.2.3