CSplinePathExtra: Collapse RemoveWaypoint loop into find_if()

This commit is contained in:
Lioncash 2020-06-20 00:00:09 -04:00
parent 487f2ae176
commit 8c06309364
2 changed files with 9 additions and 10 deletions

View File

@ -64,16 +64,15 @@ void CSplinePathExtra::AddWaypoints()
} }
} }
void CSplinePathExtra::RemoveWaypoint(CWaypointExtra *pWaypoint) void CSplinePathExtra::RemoveWaypoint(const CWaypointExtra *pWaypoint)
{ {
for (auto it = mWaypoints.begin(); it != mWaypoints.end(); ++it) const auto iter = std::find_if(mWaypoints.cbegin(), mWaypoints.cend(),
{ [pWaypoint](const auto* entry) { return entry == pWaypoint; });
if (*it == pWaypoint)
{ if (iter == mWaypoints.cend())
mWaypoints.erase(it); return;
break;
} mWaypoints.erase(iter);
}
} }
void CSplinePathExtra::ClearWaypoints() void CSplinePathExtra::ClearWaypoints()

View File

@ -24,7 +24,7 @@ public:
void FindAttachedWaypoints(std::set<CWaypointExtra*>& rChecked, CWaypointExtra* pWaypoint); void FindAttachedWaypoints(std::set<CWaypointExtra*>& rChecked, CWaypointExtra* pWaypoint);
void AddWaypoints(); void AddWaypoints();
void RemoveWaypoint(CWaypointExtra* pWaypoint); void RemoveWaypoint(const CWaypointExtra* pWaypoint);
void ClearWaypoints(); void ClearWaypoints();
}; };