diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-02-20 21:35:41 +0000 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2019-03-26 20:15:57 +0000 |
commit | 297fd3dda3abe353ebe2fe77c67b011e24d403bc (patch) | |
tree | 916615e2c4e8eaeed982b9293bea3b76a0a29374 /src/core | |
parent | 2bc2de9034d3b75a253b849cf7a703b1a503e200 (diff) | |
download | openttd-297fd3dda3abe353ebe2fe77c67b011e24d403bc.tar.xz |
Codechange: Replaced SmallVector::Include() with include()
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/smallvec_type.hpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index 0ab82c4fc..9162c17b9 100644 --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -18,6 +18,24 @@ #include <algorithm> /** + * Helper function to append an item to a vector if it is not already contained + * 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 copy-constructed if not found + * + * @return Whether the item was already present + */ +template <typename T> +inline bool include(std::vector<T>& vec, const T &item) +{ + const bool is_member = std::find(vec.begin(), vec.end(), item) != vec.end(); + if (!is_member) vec.emplace_back(item); + return is_member; +} + + +/** * Simple vector template class. * * @note There are no asserts in the class so you have @@ -67,19 +85,6 @@ public: ~SmallVector() = default; /** - * 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 - * @return true iff the item is was already present - */ - inline bool Include(const T &item) - { - bool is_member = std::find(std::vector<T>::begin(), std::vector<T>::end(), item) != std::vector<T>::end(); - if (!is_member) std::vector<T>::emplace_back(item); - return is_member; - } - - /** * Get the pointer to the first item (const) * * @return the pointer to the first item |