Codechange: Replaced SmallVector::Include() with include()

This commit is contained in:
Henry Wilson
2019-02-20 21:35:41 +00:00
committed by PeterN
parent 2bc2de9034
commit 297fd3dda3
14 changed files with 33 additions and 28 deletions

View File

@@ -17,6 +17,24 @@
#include <vector>
#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.
*
@@ -66,19 +84,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)
*