From da9ca2def28317e15a129b5a3fb060a6264f5b5e Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Sun, 17 Jan 2016 12:31:00 -0500 Subject: [PATCH] Avoid cast from const_iterator to iterator The standard library requires iterators passed to functions that modify the container to be mutable iterators, but GCC's implementation accepts const_iterator in some places where these are only used to mark a place, but the actual modification happens through a different parameter. As this breaks implementations that use the passed iterator to modify the container (e.g. because they use a different data organization), this is not portable; because we already have a non-const reference to the container anyway, this is trivially fixed as well. --- common/view/view.cpp | 2 +- pcbnew/kicad_plugin.cpp | 2 +- pcbnew/tools/drawing_tool.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 8f1933c094..6f94af86ac 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -985,7 +985,7 @@ bool VIEW::areRequiredLayersEnabled( int aLayerId ) const { wxASSERT( (unsigned) aLayerId < m_layers.size() ); - std::set::iterator it, it_end; + std::set::const_iterator it, it_end; for( it = m_layers.at( aLayerId ).requiredLayers.begin(), it_end = m_layers.at( aLayerId ).requiredLayers.end(); it != it_end; ++it ) diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index 5ae07fd9ad..2902a037e0 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -65,7 +65,7 @@ static const wxString traceFootprintLibrary( wxT( "KicadFootprintLib" ) ); ///> Removes empty nets (i.e. with node count equal zero) from net classes void filterNetClass( const BOARD& aBoard, NETCLASS& aNetClass ) { - for( NETCLASS::const_iterator it = aNetClass.begin(); it != aNetClass.end(); ) + for( NETCLASS::iterator it = aNetClass.begin(); it != aNetClass.end(); ) { NETINFO_ITEM* netinfo = aBoard.FindNet( *it ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 1ea9537567..17ce79e660 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -481,7 +481,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { delta = cursorPos - firstItem->GetPosition(); - for( KIGFX::VIEW_GROUP::iter it = preview.Begin(), end = preview.End(); it != end; ++it ) + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) static_cast( *it )->Move( wxPoint( delta.x, delta.y ) ); preview.ViewUpdate(); @@ -491,7 +491,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { - for( KIGFX::VIEW_GROUP::iter it = preview.Begin(), end = preview.End(); it != end; ++it ) + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) static_cast( *it )->Rotate( wxPoint( cursorPos.x, cursorPos.y ), m_frame->GetRotationAngle() ); @@ -499,7 +499,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { - for( KIGFX::VIEW_GROUP::iter it = preview.Begin(), end = preview.End(); it != end; ++it ) + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) static_cast( *it )->Flip( wxPoint( cursorPos.x, cursorPos.y ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); @@ -520,7 +520,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) m_frame->SaveCopyInUndoList( m_board->m_Modules, UR_MODEDIT ); m_board->m_Modules->SetLastEditTime(); - for( KIGFX::VIEW_GROUP::iter it = preview.Begin(), end = preview.End(); it != end; ++it ) + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) { BOARD_ITEM* item = static_cast( *it ); BOARD_ITEM* converted = NULL; @@ -561,7 +561,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { PICKED_ITEMS_LIST picklist; - for( KIGFX::VIEW_GROUP::iter it = preview.Begin(), end = preview.End(); it != end; ++it ) + for( KIGFX::VIEW_GROUP::const_iter it = preview.Begin(), end = preview.End(); it != end; ++it ) { BOARD_ITEM* item = static_cast( *it ); m_board->Add( item );