diff options
author | Henry Wilson <m3henry@googlemail.com> | 2018-09-23 17:36:45 +0100 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2019-03-26 20:15:57 +0000 |
commit | 81315939b909a95277ffbab51709714779089656 (patch) | |
tree | 9ee8bf1dc8e63cc0a44795ae6d23194d03bf6628 /src | |
parent | f3938fdb838685e76bba78974bb6e90e9afc6e22 (diff) | |
download | openttd-81315939b909a95277ffbab51709714779089656.tar.xz |
Codechange: Replaced SmallVector::Find() non-const with std::find()
Diffstat (limited to 'src')
-rw-r--r-- | src/animated_tile.cpp | 2 | ||||
-rw-r--r-- | src/core/pool_func.cpp | 2 | ||||
-rw-r--r-- | src/core/smallvec_type.hpp | 14 | ||||
-rw-r--r-- | src/hotkeys.cpp | 2 | ||||
-rw-r--r-- | src/network/network_content.h | 2 | ||||
-rw-r--r-- | src/train_gui.cpp | 8 | ||||
-rw-r--r-- | src/window.cpp | 2 |
7 files changed, 12 insertions, 20 deletions
diff --git a/src/animated_tile.cpp b/src/animated_tile.cpp index 5d4384820..3341f5795 100644 --- a/src/animated_tile.cpp +++ b/src/animated_tile.cpp @@ -27,7 +27,7 @@ SmallVector<TileIndex, 256> _animated_tiles; */ void DeleteAnimatedTile(TileIndex tile) { - TileIndex *to_remove = _animated_tiles.Find(tile); + TileIndex *to_remove = &*std::find(_animated_tiles.begin(), _animated_tiles.end(), tile); if (to_remove != _animated_tiles.End()) { /* The order of the remaining elements must stay the same, otherwise the animation loop may miss a tile. */ _animated_tiles.ErasePreservingOrder(to_remove); diff --git a/src/core/pool_func.cpp b/src/core/pool_func.cpp index 914cbcfd9..97f9ad1c7 100644 --- a/src/core/pool_func.cpp +++ b/src/core/pool_func.cpp @@ -21,7 +21,7 @@ /* virtual */ PoolBase::~PoolBase() { PoolVector *pools = PoolBase::GetPools(); - pools->Erase(pools->Find(this)); + pools->erase(std::find(pools->begin(), pools->end(), this)); if (pools->size() == 0) delete pools; } diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index 7e0abec76..289cc9e1d 100644 --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -120,20 +120,6 @@ public: * 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 End() when not present - */ - inline T *Find(const T &item) - { - T *pos = this->Begin(); - const T *end = this->End(); - while (pos != end && *pos != item) pos++; - return pos; - } - - /** - * 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 diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index 9411887ea..9f323bc28 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -260,7 +260,7 @@ HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandler HotkeyList::~HotkeyList() { - _hotkey_lists->Erase(_hotkey_lists->Find(this)); + _hotkey_lists->erase(std::find(_hotkey_lists->begin(), _hotkey_lists->end(), this)); } /** diff --git a/src/network/network_content.h b/src/network/network_content.h index 0d30de857..a81cc6a6d 100644 --- a/src/network/network_content.h +++ b/src/network/network_content.h @@ -142,7 +142,7 @@ public: /** Add a callback to this class */ void AddCallback(ContentCallback *cb) { this->callbacks.Include(cb); } /** Remove a callback */ - void RemoveCallback(ContentCallback *cb) { this->callbacks.Erase(this->callbacks.Find(cb)); } + void RemoveCallback(ContentCallback *cb) { this->callbacks.erase(std::find(this->callbacks.begin(), this->callbacks.end(), cb)); } }; extern ClientNetworkContentSocketHandler _network_content_client; diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 3c394ef19..eab6a33e3 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -174,6 +174,12 @@ struct CargoSummaryItem { { return this->cargo != other.cargo || this->subtype != other.subtype; } + + /** Used by std::find() and similar functions */ + inline bool operator == (const CargoSummaryItem &other) const + { + return !(this->cargo != other.cargo); + } }; static const uint TRAIN_DETAILS_MIN_INDENT = 32; ///< Minimum indent level in the train details window @@ -272,7 +278,7 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary *su new_item.subtype = GetCargoSubtypeText(v); if (new_item.cargo == INVALID_CARGO && new_item.subtype == STR_EMPTY) continue; - CargoSummaryItem *item = summary->Find(new_item); + CargoSummaryItem *item = &*std::find(summary->begin(), summary->end(), new_item); if (item == summary->End()) { item = summary->Append(); item->cargo = new_item.cargo; diff --git a/src/window.cpp b/src/window.cpp index c6a9f1653..471ac08a2 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -114,7 +114,7 @@ WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_wi WindowDesc::~WindowDesc() { - _window_descs->Erase(_window_descs->Find(this)); + _window_descs->erase(std::find(_window_descs->begin(), _window_descs->end(), this)); } /** |