Changeset - r27321:bd1380ce5d71
[Not reviewed]
master
0 1 0
Peter Nelson - 16 months ago 2023-05-09 20:51:46
peter1138@openttd.org
Codechange: Use find_if when finding things.
1 file changed with 1 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/core/smallmap_type.hpp
Show inline comments
 
@@ -31,29 +31,25 @@ struct SmallMap : std::vector<std::pair<
 
	/** Creates new SmallMap. Data are initialized in std::vector constructor */
 
	inline SmallMap() { }
 
	/** Data are freed in std::vector destructor */
 
	inline ~SmallMap() { }
 

	
 
	/**
 
	 * Finds given key in this map
 
	 * @param key key to find
 
	 * @return &Pair(key, data) if found, this->End() if not
 
	 */
 
	inline typename std::vector<Pair>::const_iterator Find(const T &key) const
 
	{
 
		typename std::vector<Pair>::const_iterator it;
 
		for (it = std::vector<Pair>::begin(); it != std::vector<Pair>::end(); it++) {
 
			if (key == it->first) return it;
 
		}
 
		return it;
 
		return std::find_if(std::vector<Pair>::begin(), std::vector<Pair>::end(), [&key](const Pair &pair) { return key == pair.first; });
 
	}
 

	
 
	/**
 
	 * Finds given key in this map
 
	 * @param key key to find
 
	 * @return &Pair(key, data) if found, this->End() if not
 
	 */
 
	inline Pair *Find(const T &key)
 
	{
 
		for (uint i = 0; i < std::vector<Pair>::size(); i++) {
 
			if (key == std::vector<Pair>::operator[](i).first) return &std::vector<Pair>::operator[](i);
 
		}
0 comments (0 inline, 0 general)