diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index 8b0728c7cc..276e094b4b 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -30,19 +30,6 @@ #include "simulation2/components/ICmpTerrain.h" #include "simulation2/components/ICmpVisual.h" -template -static void delete_pair_2nd(std::pair v) -{ - delete v.second; -} - -template -struct second_equals -{ - T x; - second_equals(const T& x) : x(x) {} - template bool operator()(const S& v) { return v.second == x; } -}; bool CObjectManager::ObjectKey::operator< (const CObjectManager::ObjectKey& a) const { @@ -170,9 +157,12 @@ CTerrain* CObjectManager::GetTerrain() void CObjectManager::DeleteObject(CObjectEntry* entry) { - std::map::iterator it; - while (m_Objects.end() != (it = find_if(m_Objects.begin(), m_Objects.end(), second_equals(entry)))) - m_Objects.erase(it); + std::function&)> second_equals = + [&entry](const std::pair& a) { return a.second == entry; }; + + std::map::iterator it = m_Objects.begin(); + while (m_Objects.end() != (it = find_if(it, m_Objects.end(), second_equals))) + it = m_Objects.erase(it); delete entry; } @@ -180,18 +170,12 @@ void CObjectManager::DeleteObject(CObjectEntry* entry) void CObjectManager::UnloadObjects() { - std::for_each( - m_Objects.begin(), - m_Objects.end(), - delete_pair_2nd - ); + for (const std::pair& p : m_Objects) + delete p.second; m_Objects.clear(); - std::for_each( - m_ObjectBases.begin(), - m_ObjectBases.end(), - delete_pair_2nd - ); + for (const std::pair& p : m_ObjectBases) + delete p.second; m_ObjectBases.clear(); } diff --git a/source/graphics/ShaderManager.cpp b/source/graphics/ShaderManager.cpp index 8ad36662d4..007b9f5d66 100644 --- a/source/graphics/ShaderManager.cpp +++ b/source/graphics/ShaderManager.cpp @@ -37,14 +37,6 @@ TIMER_ADD_CLIENT(tc_ShaderValidation); -struct revcompare2nd -{ - template bool operator()(const std::pair& a, const std::pair& b) const - { - return b.second < a.second; - } -}; - CShaderManager::CShaderManager() { #if USE_SHADER_XML_VALIDATION @@ -498,7 +490,10 @@ bool CShaderManager::NewEffect(const char* name, const CShaderDefines& baseDefin } // Sort by preference, tie-break on order of specification - std::stable_sort(usableTechs.begin(), usableTechs.end(), revcompare2nd()); + std::stable_sort(usableTechs.begin(), usableTechs.end(), + [](const std::pair& a, const std::pair& b) { + return b.second < a.second; + }); CShaderDefines techDefines = baseDefines; diff --git a/source/ps/GameSetup/CmdLineArgs.cpp b/source/ps/GameSetup/CmdLineArgs.cpp index 2f61839c98..b4e280a240 100644 --- a/source/ps/GameSetup/CmdLineArgs.cpp +++ b/source/ps/GameSetup/CmdLineArgs.cpp @@ -55,22 +55,16 @@ CmdLineArgs::CmdLineArgs(int argc, const char* argv[]) } } -template -struct first_equals -{ - T x; - first_equals(const T& x) : x(x) {} - template bool operator()(const S& v) { return v.first == x; } -}; - bool CmdLineArgs::Has(const char* name) const { - return find_if(m_Args.begin(), m_Args.end(), first_equals(name)) != m_Args.end(); + return m_Args.end() != find_if(m_Args.begin(), m_Args.end(), + [&name](const std::pair& a) { return a.first == name; }); } CStr CmdLineArgs::Get(const char* name) const { - ArgsT::const_iterator it = find_if(m_Args.begin(), m_Args.end(), first_equals(name)); + ArgsT::const_iterator it = find_if(m_Args.begin(), m_Args.end(), + [&name](const std::pair& a) { return a.first == name; }); if (it != m_Args.end()) return it->second; else @@ -83,7 +77,8 @@ std::vector CmdLineArgs::GetMultiple(const char* name) const ArgsT::const_iterator it = m_Args.begin(); while (1) { - it = find_if(it, m_Args.end(), first_equals(name)); + it = find_if(it, m_Args.end(), + [&name](const std::pair& a) { return a.first == name; }); if (it == m_Args.end()) break; values.push_back(it->second); diff --git a/source/renderer/TerrainOverlay.cpp b/source/renderer/TerrainOverlay.cpp index 431badc200..d01b42fc28 100644 --- a/source/renderer/TerrainOverlay.cpp +++ b/source/renderer/TerrainOverlay.cpp @@ -33,32 +33,6 @@ #include -// Handy things for STL: - -/// Functor for sorting pairs, using the <-ordering of their second values. -struct compare2nd -{ - template bool operator()(const std::pair& a, const std::pair& b) const - { - return a.second < b.second; - } -}; - -/// Functor for comparing the firsts of pairs to a specified value. -template struct equal1st -{ - const S& val; - equal1st(const S& val) : val(val) {} - template bool operator()(const std::pair& a) const - { - return a.first == val; - } -private: - const equal1st& operator=(const equal1st& rhs); -}; - -////////////////////////////////////////////////////////////////////////// - // Global overlay list management: static std::vector > g_TerrainOverlayList; @@ -71,14 +45,16 @@ ITerrainOverlay::ITerrainOverlay(int priority) // overlays doesn't randomly disturb all the existing ones (which would // be noticeable if they have the same priority and overlap). std::stable_sort(g_TerrainOverlayList.begin(), g_TerrainOverlayList.end(), - compare2nd()); + [](const std::pair& a, const std::pair& b) { + return a.second < b.second; + }); } ITerrainOverlay::~ITerrainOverlay() { std::vector >::iterator newEnd = std::remove_if(g_TerrainOverlayList.begin(), g_TerrainOverlayList.end(), - equal1st(this)); + [this](const std::pair& a) { return a.first == this; }); g_TerrainOverlayList.erase(newEnd, g_TerrainOverlayList.end()); } diff --git a/source/simulation2/helpers/Selection.cpp b/source/simulation2/helpers/Selection.cpp index 64634f4ef9..856d9eed1e 100644 --- a/source/simulation2/helpers/Selection.cpp +++ b/source/simulation2/helpers/Selection.cpp @@ -31,12 +31,6 @@ #include "ps/CLogger.h" #include "ps/Profiler2.h" -namespace { -struct SortFun { - bool operator() (std::pair i, std::pair j) { return (i.first& a, const std::pair& b) { + return a.first < b.first; + }); CmpPtr cmpRangeManager(simulation, SYSTEM_ENTITY); ENSURE(cmpRangeManager); diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 1821e6fdfb..116c31a146 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -165,12 +165,6 @@ void AtlasViewActor::SetParam(const std::wstring& name, const AtlasMessage::Colo ////////////////////////////////////////////////////////////////////////// -template -static void delete_pair_2nd(std::pair v) -{ - delete v.second; -} - AtlasViewGame::AtlasViewGame() : m_SpeedMultiplier(0.f), m_IsTesting(false) { @@ -179,7 +173,8 @@ AtlasViewGame::AtlasViewGame() AtlasViewGame::~AtlasViewGame() { - std::for_each(m_SavedStates.begin(), m_SavedStates.end(), delete_pair_2nd); + for (const std::pair& p : m_SavedStates) + delete p.second; } CSimulation2* AtlasViewGame::GetSimulation2()