summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenry Wilson <m3henry@googlemail.com>2018-09-25 22:01:05 +0100
committerPeterN <peter@fuzzle.org>2019-03-26 20:15:57 +0000
commitca2f33c6d025c0c45fb4bc472493290445312de5 (patch)
treecf39f3f0a815778049c037d80f0b86a11f1af665 /src
parent097328c3d73520834b4ef801945c4f57f9eca0cd (diff)
downloadopenttd-ca2f33c6d025c0c45fb4bc472493290445312de5.tar.xz
Codechange: Replaced SmallVector::Erase() with std::vector::erase()
Diffstat (limited to 'src')
-rw-r--r--src/core/smallmap_type.hpp10
-rw-r--r--src/core/smallvec_type.hpp12
-rw-r--r--src/network/core/tcp_connect.cpp8
-rw-r--r--src/network/core/tcp_http.cpp4
-rw-r--r--src/newgrf_debug_gui.cpp2
-rw-r--r--src/sortlist_type.h9
-rw-r--r--src/station_cmd.cpp8
-rw-r--r--src/station_gui.cpp4
8 files changed, 22 insertions, 35 deletions
diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp
index 44ace6b45..0bd9bd296 100644
--- a/src/core/smallmap_type.hpp
+++ b/src/core/smallmap_type.hpp
@@ -115,7 +115,8 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
inline void Erase(Pair *pair)
{
assert(pair >= this->Begin() && pair < this->End());
- SmallVector<Pair, S>::Erase(pair);
+ auto distance = pair - std::vector<Pair>::data();
+ std::vector<Pair>::erase(std::vector<Pair>::begin() + distance);
}
/**
@@ -126,11 +127,10 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
*/
inline bool Erase(const T &key)
{
- Pair *pair = this->Find(key);
- if (pair == this->End())
- return false;
+ auto pair = std::find(this->begin(), this->end(), key);
+ if (pair == this->end()) return false;
- SmallVector<Pair, S>::Erase(pair);
+ std::vector<Pair>::erase(pair);
return true;
}
diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp
index 1ec336b73..b989d44c5 100644
--- a/src/core/smallvec_type.hpp
+++ b/src/core/smallvec_type.hpp
@@ -104,18 +104,6 @@ public:
}
/**
- * Removes given item from this vector
- * @param item item to remove
- * @note it has to be pointer to item in this map. It is overwritten by the last item.
- */
- inline void Erase(T *item)
- {
- assert(item >= this->Begin() && item < this->End());
- *item = std::vector<T>::back();
- std::vector<T>::pop_back();
- }
-
- /**
* 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
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index 95f9662cd..470d97e68 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -66,22 +66,22 @@ void TCPConnecter::Connect()
*/
/* static */ void TCPConnecter::CheckCallbacks()
{
- for (TCPConnecter **iter = _tcp_connecters.Begin(); iter < _tcp_connecters.End(); /* nothing */) {
+ for (auto iter = _tcp_connecters.begin(); iter < _tcp_connecters.end(); /* nothing */) {
TCPConnecter *cur = *iter;
if ((cur->connected || cur->aborted) && cur->killed) {
- _tcp_connecters.Erase(iter);
+ iter = _tcp_connecters.erase(iter);
if (cur->sock != INVALID_SOCKET) closesocket(cur->sock);
delete cur;
continue;
}
if (cur->connected) {
- _tcp_connecters.Erase(iter);
+ iter = _tcp_connecters.erase(iter);
cur->OnConnect(cur->sock);
delete cur;
continue;
}
if (cur->aborted) {
- _tcp_connecters.Erase(iter);
+ iter = _tcp_connecters.erase(iter);
cur->OnFailure();
delete cur;
continue;
diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp
index d2ab0638c..2d3e89b4e 100644
--- a/src/network/core/tcp_http.cpp
+++ b/src/network/core/tcp_http.cpp
@@ -311,7 +311,7 @@ int NetworkHTTPSocketHandler::Receive()
int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv);
if (n == -1) return;
- for (NetworkHTTPSocketHandler **iter = _http_connections.Begin(); iter < _http_connections.End(); /* nothing */) {
+ for (auto iter = _http_connections.begin(); iter < _http_connections.end(); /* nothing */) {
NetworkHTTPSocketHandler *cur = *iter;
if (FD_ISSET(cur->sock, &read_fd)) {
@@ -321,7 +321,7 @@ int NetworkHTTPSocketHandler::Receive()
if (ret <= 0) {
/* Then... the connection can be closed */
cur->CloseConnection();
- _http_connections.Erase(iter);
+ iter = _http_connections.erase(iter);
delete cur;
continue;
}
diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp
index ec1a91d7b..a08124357 100644
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -986,7 +986,7 @@ struct SpriteAlignerWindow : Window {
case WID_SA_RESET_REL:
/* Reset the starting offsets for the current sprite. */
- this->offs_start_map.Erase(this->current_sprite);
+ this->offs_start_map.erase(this->offs_start_map.begin() + this->current_sprite);
this->SetDirty();
break;
}
diff --git a/src/sortlist_type.h b/src/sortlist_type.h
index 74b6f37b3..23a558018 100644
--- a/src/sortlist_type.h
+++ b/src/sortlist_type.h
@@ -337,13 +337,12 @@ public:
if (!(this->flags & VL_FILTER)) return false;
bool changed = false;
- for (uint iter = 0; iter < std::vector<T>::size();) {
- T *item = &std::vector<T>::operator[](iter);
- if (!decide(item, filter_data)) {
- this->Erase(item);
+ for (auto it = std::vector<T>::begin(); it != std::vector<T>::end(); /* Nothing */) {
+ if (!decide(&*it, filter_data)) {
+ it = std::vector<T>::erase(it);
changed = true;
} else {
- iter++;
+ it++;
}
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index f7e2a1824..2dee09fe8 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -3541,8 +3541,8 @@ void DeleteStaleLinks(Station *from)
*(vehicles.Append()) = l->GetFirstSharedVehicle();
}
- Vehicle **iter = vehicles.Begin();
- while (iter != vehicles.End()) {
+ auto iter = vehicles.begin();
+ while (iter != vehicles.end()) {
Vehicle *v = *iter;
LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
@@ -3556,10 +3556,10 @@ void DeleteStaleLinks(Station *from)
*iter = next_shared;
++iter;
} else {
- vehicles.Erase(iter);
+ iter = vehicles.erase(iter);
}
- if (iter == vehicles.End()) iter = vehicles.Begin();
+ if (iter == vehicles.end()) iter = vehicles.begin();
}
}
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 157d571af..e1f5daa69 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -2133,10 +2133,10 @@ static bool AddNearbyStation(TileIndex tile, void *user_data)
/* First check if there were deleted stations here */
for (uint i = 0; i < _deleted_stations_nearby.size(); i++) {
- TileAndStation *ts = _deleted_stations_nearby.data() + i;
+ auto ts = _deleted_stations_nearby.begin() + i;
if (ts->tile == tile) {
*_stations_nearby_list.Append() = _deleted_stations_nearby[i].station;
- _deleted_stations_nearby.Erase(ts);
+ _deleted_stations_nearby.erase(ts);
i--;
}
}