summaryrefslogtreecommitdiff
path: root/common/list.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/list.h')
-rw-r--r--common/list.h34
1 files changed, 34 insertions, 0 deletions
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 <vector>
+#include <algorithm>
+#include <boost/serialization/base_object.hpp>
+
+//! List class with extended functionality over std::vector.
+template<class T, class B = std::vector<T> >
+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<class Archive>
+ void serialize(Archive & ar, const unsigned int version) {
+ ar & boost::serialization::base_object<B>(*this);
+ }
+};
+
+#endif