summaryrefslogtreecommitdiff
path: root/src/core/smallvec_type.hpp
diff options
context:
space:
mode:
authorHenry Wilson <m3henry@googlemail.com>2019-02-20 19:27:10 +0000
committerPeterN <peter@fuzzle.org>2019-03-26 20:15:57 +0000
commit2bc2de9034d3b75a253b849cf7a703b1a503e200 (patch)
tree39f3a8e94a6f993f20dbbf027b6cdd684ab4ce4c /src/core/smallvec_type.hpp
parente0c58bf5ee0f3f4d0563a04de315c09b37f74c6e (diff)
downloadopenttd-2bc2de9034d3b75a253b849cf7a703b1a503e200.tar.xz
Codechange: Replaced SmallVector::Find() with std::find()
Diffstat (limited to 'src/core/smallvec_type.hpp')
-rw-r--r--src/core/smallvec_type.hpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index e0596e338..0ab82c4fc 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -67,18 +67,6 @@ public:
~SmallVector() = default;
/**
- * Search for the first occurrence of an item.
- * The '!=' operator of T is used for comparison.
- * @param item Item to search for
- * @return The position of the item, or -1 when not present
- */
- inline int FindIndex(const T &item) const
- {
- auto const it = std::find(std::vector<T>::begin(), std::vector<T>::end(), item);
- return it == std::vector<T>::end() ? -1 : it - std::vector<T>::begin();
- }
-
- /**
* Tests whether a item is present in the vector, and appends it to the end if not.
* The '!=' operator of T is used for comparison.
* @param item Item to test for
@@ -133,7 +121,25 @@ public:
};
/**
- * Helper function to extend a vector by more than one element
+ * Helper function to get the index of an item
+ * Consider using std::set, std::unordered_set or std::flat_set in new code
+ *
+ * @param vec A reference to the vector to be extended
+ * @param item Reference to the item to be search for
+ *
+ * @return Index of element if found, otherwise -1
+ */
+template <typename T>
+int find_index(std::vector<T> const& vec, T const& item)
+{
+ auto const it = std::find(vec.begin(), vec.end(), item);
+ if (it != vec.end()) return it - vec.begin();
+
+ return -1;
+}
+
+/**
+ * Helper function to append N default-constructed elements and get a pointer to the first new element
* Consider using std::back_inserter in new code
*
* @param vec A reference to the vector to be extended