diff --git a/common/commit.cpp b/common/commit.cpp index ebfd3d7488..e81ae40f69 100644 --- a/common/commit.cpp +++ b/common/commit.cpp @@ -25,8 +25,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include - +#include #include #include #include @@ -137,16 +136,6 @@ int COMMIT::GetStatus( EDA_ITEM* aItem ) } -template -void eraseIf( Container& c, F&& f ) -{ - c.erase( std::remove_if( c.begin(), - c.end(), - std::forward( f ) ), - c.end() ); -} - - COMMIT& COMMIT::createModified( EDA_ITEM* aItem, EDA_ITEM* aCopy, int aExtraFlags ) { EDA_ITEM* parent = parentObject( aItem ); @@ -171,10 +160,10 @@ void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy ) if( m_changedItems.find( aItem ) != m_changedItems.end() ) { - eraseIf( m_changes, [aItem] ( const COMMIT_LINE& aEnt ) - { - return aEnt.m_item == aItem; - } ); + alg::delete_if( m_changes, [aItem]( const COMMIT_LINE& aEnt ) + { + return aEnt.m_item == aItem; + } ); } COMMIT_LINE ent; diff --git a/common/lib_table_base.cpp b/common/lib_table_base.cpp index 59b58bbe59..c6e2626adb 100644 --- a/common/lib_table_base.cpp +++ b/common/lib_table_base.cpp @@ -292,10 +292,11 @@ std::vector LIB_TABLE::GetLogicalLibs() } // We want to allow case-sensitive duplicates but sort by case-insensitive ordering - std::sort( ret.begin(), ret.end(), []( const wxString& lhs, const wxString& rhs ) - { - return lhs.CmpNoCase( rhs ) < 0; - } ); + std::sort( ret.begin(), ret.end(), + []( const wxString& lhs, const wxString& rhs ) + { + return lhs.CmpNoCase( rhs ) < 0; + } ); return ret; } diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index a67a77f556..c169f142a2 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -24,7 +24,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include #include #include diff --git a/eeschema/bus_alias.cpp b/eeschema/bus_alias.cpp index 23a3499a9d..04d4a7e840 100644 --- a/eeschema/bus_alias.cpp +++ b/eeschema/bus_alias.cpp @@ -18,8 +18,6 @@ * with this program. If not, see . */ -#include -#include #include #include "bus_alias.h" diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 078e78ab97..2b4f047cd3 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -22,12 +22,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -1054,7 +1054,7 @@ void CONNECTION_GRAPH::buildConnectionGraph() wxLogTrace( ConnTrace, "%ld (%s) is weakly driven and not unique. Changing to %s.", subgraph->m_code, name, new_name ); - vec->erase( std::remove( vec->begin(), vec->end(), subgraph ), vec->end() ); + alg::delete_matching( *vec, subgraph ); m_net_name_to_subgraphs_map[new_name].emplace_back( subgraph ); @@ -1307,12 +1307,10 @@ void CONNECTION_GRAPH::buildConnectionGraph() } // Absorbed subgraphs should no longer be considered - m_driver_subgraphs.erase( std::remove_if( m_driver_subgraphs.begin(), m_driver_subgraphs.end(), - [&] ( const CONNECTION_SUBGRAPH* candidate ) -> bool - { - return candidate->m_absorbed; - } ), - m_driver_subgraphs.end() ); + alg::delete_if( m_driver_subgraphs, [&]( const CONNECTION_SUBGRAPH* candidate ) -> bool + { + return candidate->m_absorbed; + } ); // Store global subgraphs for later reference std::vector global_subgraphs; @@ -2031,7 +2029,7 @@ void CONNECTION_GRAPH::recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, if( it != m_net_name_to_subgraphs_map.end() ) { std::vector& vec = it->second; - vec.erase( std::remove( vec.begin(), vec.end(), aSubgraph ), vec.end() ); + alg::delete_matching( vec, aSubgraph ); } wxLogTrace( ConnTrace, "recacheSubgraphName: %s => %s", aOldName, diff --git a/eeschema/dialogs/dialog_choose_symbol.cpp b/eeschema/dialogs/dialog_choose_symbol.cpp index 545d8d03c9..7bea064c5c 100644 --- a/eeschema/dialogs/dialog_choose_symbol.cpp +++ b/eeschema/dialogs/dialog_choose_symbol.cpp @@ -22,12 +22,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include #include #include #include #include +#include #include #include #include @@ -487,12 +487,10 @@ void DIALOG_CHOOSE_SYMBOL::OnFootprintSelected( wxCommandEvent& aEvent ) { m_fp_override = aEvent.GetString(); - m_field_edits.erase( std::remove_if( m_field_edits.begin(), m_field_edits.end(), - []( std::pair const& i ) - { - return i.first == FOOTPRINT_FIELD; - } ), - m_field_edits.end() ); + alg::delete_if( m_field_edits, []( std::pair const& i ) + { + return i.first == FOOTPRINT_FIELD; + } ); m_field_edits.emplace_back( std::make_pair( FOOTPRINT_FIELD, m_fp_override ) ); diff --git a/eeschema/dialogs/dialog_spice_model.cpp b/eeschema/dialogs/dialog_spice_model.cpp index 7e6d78dde9..1321a37619 100644 --- a/eeschema/dialogs/dialog_spice_model.cpp +++ b/eeschema/dialogs/dialog_spice_model.cpp @@ -27,6 +27,7 @@ #include "dialog_spice_model.h" #include +#include #include #include #include @@ -311,21 +312,17 @@ bool DIALOG_SPICE_MODEL::TransferDataFromWindow() if( m_useSchFields ) { - m_schfields->erase( std::remove_if( m_schfields->begin(), m_schfields->end(), - [&]( const SCH_FIELD& f ) - { - return f.GetName() == spiceField; - } ), - m_schfields->end() ); + alg::delete_if( *m_schfields, [&]( const SCH_FIELD& f ) + { + return f.GetName() == spiceField; + } ); } else { - m_libfields->erase( std::remove_if( m_libfields->begin(), m_libfields->end(), - [&]( const LIB_FIELD& f ) - { - return f.GetName() == spiceField; - } ), - m_libfields->end() ); + alg::delete_if( *m_libfields, [&]( const LIB_FIELD& f ) + { + return f.GetName() == spiceField; + } ); } } } diff --git a/eeschema/dialogs/dialog_update_symbol_fields.cpp b/eeschema/dialogs/dialog_update_symbol_fields.cpp index d4d7912b22..853c1f6e20 100644 --- a/eeschema/dialogs/dialog_update_symbol_fields.cpp +++ b/eeschema/dialogs/dialog_update_symbol_fields.cpp @@ -18,8 +18,6 @@ * with this program. If not, see . */ -#include - #include #include #include diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index bfc3aacfbc..f3ccf10f9d 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -23,7 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include #include #include @@ -181,12 +181,10 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SCHLIB_FILTER* aFilte if( sel.LibId.IsValid() ) { - aHistoryList.erase( std::remove_if( aHistoryList.begin(), aHistoryList.end(), - [ &sel ]( PICKED_SYMBOL const& i ) - { - return i.LibId == sel.LibId; - } ), - aHistoryList.end() ); + alg::delete_if( aHistoryList, [&sel]( PICKED_SYMBOL const& i ) + { + return i.LibId == sel.LibId; + } ); aHistoryList.insert( aHistoryList.begin(), sel ); } diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 2745cf2c08..19b8f637d3 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,6 @@ #include #include - SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_ITEM* aParent, const wxString& aName ) : SCH_ITEM( aParent, SCH_FIELD_T ), @@ -531,19 +531,21 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) std::vector pageListCopy; pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() ); - std::sort( pageListCopy.begin(), pageListCopy.end() ); - if( !Schematic()->Settings().m_IntersheetRefsListOwnPage ) { wxString currentPage = Schematic()->CurrentSheet().GetPageNumber(); - pageListCopy.erase( std::remove( pageListCopy.begin(), - pageListCopy.end(), - currentPage ), pageListCopy.end() ); + alg::delete_matching( pageListCopy, currentPage ); if( pageListCopy.empty() ) return; } + std::sort( pageListCopy.begin(), pageListCopy.end(), + []( const wxString& a, const wxString& b ) -> bool + { + return StrNumCmp( a, b, true ) < 0; + } ); + for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() ) { if( sheet.size() == 1 ) diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 231c10304b..61bee381d6 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include using KIGFX::SCH_RENDER_SETTINGS; @@ -1249,14 +1250,16 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const std::vector pageListCopy; pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() ); - std::sort( pageListCopy.begin(), pageListCopy.end() ); + std::sort( pageListCopy.begin(), pageListCopy.end(), + []( const wxString& a, const wxString& b ) -> bool + { + return StrNumCmp( a, b, true ) <= 0; + } ); if( !settings.m_IntersheetRefsListOwnPage ) { wxString currentPage = Schematic()->CurrentSheet().GetPageNumber(); - pageListCopy.erase( std::remove( pageListCopy.begin(), - pageListCopy.end(), - currentPage ), pageListCopy.end() ); + alg::delete_matching( pageListCopy, currentPage ); } if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) ) diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index b203f38477..50b640139e 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -66,7 +66,6 @@ #include #include #include -//#include #include diff --git a/include/collector.h b/include/collector.h index 752e5cfb54..9543c2eed9 100644 --- a/include/collector.h +++ b/include/collector.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,16 +22,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file collector.h - * @brief COLLECTOR class definition. - */ - #ifndef COLLECTOR_H #define COLLECTOR_H #include - +#include #include // SEARCH_RESULT #include @@ -124,12 +119,10 @@ public: */ void Remove( const EDA_ITEM* aItem ) { - m_list.erase( std::remove_if( m_list.begin(), m_list.end(), - [&aItem]( const EDA_ITEM* aCandidate ) - { - return aCandidate == aItem; - } ), - m_list.end() ); + alg::delete_if( m_list, [&aItem]( const EDA_ITEM* aCandidate ) + { + return aCandidate == aItem; + } ); } /** diff --git a/include/core/kicad_algo.h b/include/core/kicad_algo.h index 2eefbf0fa4..fb06ed97f4 100644 --- a/include/core/kicad_algo.h +++ b/include/core/kicad_algo.h @@ -153,6 +153,28 @@ bool within_wrapped_range( T __val, T __minval, T __maxval, T __wrap ) return __val >= __minval || __val <= __maxval; } +/** + * Covers for the horrifically named std::remove and std::remove_if (neither of which remove + * anything). + */ +/** + * @brief Deletes all values from \a __c which match \a __value. + */ +template +void delete_matching( _Container& __c, _Value __value ) +{ + __c.erase( std::remove( __c.begin(), __c.end(), __value ), __c.end() ); +} + +/** + * @brief Deletes all values from \a __c for which \a __f returns true. + */ +template +void delete_if( _Container& __c, _Function&& __f ) +{ + __c.erase( std::remove_if( __c.begin(), __c.end(), std::forward<_Function>( __f ) ), __c.end() ); +} + } // namespace alg diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index f51f6d58ee..b554fd0838 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -25,7 +25,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include // for INT_MAX #include // for hypot #include diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 7dbc1aeab4..dbacbaf359 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -25,7 +25,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include #include #include @@ -744,45 +743,25 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode ) } case PCB_MARKER_T: - m_markers.erase( std::remove_if( m_markers.begin(), m_markers.end(), - [aBoardItem]( BOARD_ITEM* aItem ) - { - return aItem == aBoardItem; - } ) ); + alg::delete_matching( m_markers, aBoardItem ); break; case PCB_GROUP_T: - m_groups.erase( std::remove_if( m_groups.begin(), m_groups.end(), - [aBoardItem]( BOARD_ITEM* aItem ) - { - return aItem == aBoardItem; - } ) ); + alg::delete_matching( m_groups, aBoardItem ); break; case PCB_ZONE_T: - m_zones.erase( std::remove_if( m_zones.begin(), m_zones.end(), - [aBoardItem]( BOARD_ITEM* aItem ) - { - return aItem == aBoardItem; - } ) ); + alg::delete_matching( m_zones, aBoardItem ); break; case PCB_FOOTPRINT_T: - m_footprints.erase( std::remove_if( m_footprints.begin(), m_footprints.end(), - [aBoardItem]( BOARD_ITEM* aItem ) - { - return aItem == aBoardItem; - } ) ); + alg::delete_matching( m_footprints, aBoardItem ); break; case PCB_TRACE_T: case PCB_ARC_T: case PCB_VIA_T: - m_tracks.erase( std::remove_if( m_tracks.begin(), m_tracks.end(), - [aBoardItem]( BOARD_ITEM* aItem ) - { - return aItem == aBoardItem; - } ) ); + alg::delete_matching( m_tracks, aBoardItem ); break; case PCB_DIM_ALIGNED_T: @@ -792,11 +771,7 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode ) case PCB_SHAPE_T: case PCB_TEXT_T: case PCB_TARGET_T: - m_drawings.erase( std::remove_if( m_drawings.begin(), m_drawings.end(), - [aBoardItem](BOARD_ITEM* aItem) - { - return aItem == aBoardItem; - } ) ); + alg::delete_matching( m_drawings, aBoardItem ); break; // other types may use linked list diff --git a/pcbnew/dialogs/dialog_net_inspector.cpp b/pcbnew/dialogs/dialog_net_inspector.cpp index 0f10cc25c7..4d0427f6db 100644 --- a/pcbnew/dialogs/dialog_net_inspector.cpp +++ b/pcbnew/dialogs/dialog_net_inspector.cpp @@ -1563,9 +1563,7 @@ void DIALOG_NET_INSPECTOR::buildNetsList() m_netsList->UnselectAll(); } - prev_selected_netcodes.erase( std::remove( prev_selected_netcodes.begin(), - prev_selected_netcodes.end(), -1 ), - prev_selected_netcodes.end() ); + alg::delete_matching( prev_selected_netcodes, -1 ); m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( false ); diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.cpp b/pcbnew/plugins/fabmaster/import_fabmaster.cpp index b194286778..d45f6ccac2 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.cpp +++ b/pcbnew/plugins/fabmaster/import_fabmaster.cpp @@ -206,16 +206,13 @@ FABMASTER::section_type FABMASTER::detectType( size_t aOffset ) std::string row3{}; /// We strip the underscores from all column names as some export variants use them and some do not - row1.erase( std::remove_if( row1.begin(), row1.end(), []( char c ){ return c == '_'; } ), - row1.end() ); - row2.erase( std::remove_if( row2.begin(), row2.end(), []( char c ){ return c == '_'; } ), - row2.end() ); + alg::delete_if( row1, []( char c ){ return c == '_'; } ); + alg::delete_if( row2, []( char c ){ return c == '_'; } ); if( row.size() > 3 ) { row3 = row[3]; - row3.erase( std::remove_if( row3.begin(), row3.end(), []( char c ){ return c == '_'; } ), - row3.end() ); + alg::delete_if( row3, []( char c ){ return c == '_'; } ); } if( row1 == "REFDES" && row2 == "COMPCLASS" ) @@ -303,14 +300,13 @@ int FABMASTER::getColFromName( size_t aRow, const std::string& aStr ) if( aRow >= rows.size() ) return -1; - auto header = rows[aRow]; + std::vector header = rows[aRow]; for( size_t i = 0; i < header.size(); i++ ) { /// Some Fabmaster headers include the underscores while others do not /// so we strip them uniformly before comparing - header[i].erase( std::remove_if( header[i].begin(), header[i].end(), - []( const char c ){ return c == '_'; } ), header[i].end() ); + alg::delete_if( header[i], []( const char c ) { return c == '_'; } ); if( header[i] == aStr ) return i; diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index a09925da56..435ece940b 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -24,9 +24,8 @@ */ #include -#include #include - +#include #include #include #include @@ -284,12 +283,10 @@ bool ZONE_FILLER::Fill( std::vector& aZones, bool aCheck, wxWindow* aPare } } - toFill.erase( std::remove_if( toFill.begin(), toFill.end(), - [&] ( const std::pair pair ) -> bool - { - return pair.first->GetFillFlag( pair.second ); - } ), - toFill.end() ); + alg::delete_if( toFill, [&]( const std::pair pair ) -> bool + { + return pair.first->GetFillFlag( pair.second ); + } ); if( m_progressReporter && m_progressReporter->IsCancelled() ) break;