← Back to team overview

kicad-developers team mailing list archive

[PATCH 04/11] 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 8f1933c..6f94af8 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<int>::iterator it, it_end;
+    std::set<int>::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 5ae07fd..2902a03 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 1ea9537..17ce79e 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<BOARD_ITEM*>( *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<BOARD_ITEM*>( *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<BOARD_ITEM*>( *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<BOARD_ITEM*>( *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<BOARD_ITEM*>( *it );
                     m_board->Add( item );

Follow ups

References