← Back to team overview

kicad-developers team mailing list archive

[PATCH] Avoid cast from const_iterator to iterator

 

Hi,

this repairs const correctness for some STL container accesses:

- The result of .begin() and .end() on a const reference is a const_iterator.
- The .erase() function requires a mutable iterator.

The GNU C++ stdlib actually uses the same type here, because set members
may not be manipulated through an iterator (because the set is sorted), but
that is not a contractual guarantee.

   Simon

---
 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 d701b83..8fbb9c3 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 a3a889f..e5f6030 100644
--- a/pcbnew/tools/drawing_tool.cpp
+++ b/pcbnew/tools/drawing_tool.cpp
@@ -514,7 +514,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();
@@ -524,7 +524,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() );
 
@@ -532,7 +532,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 );
@@ -552,7 +552,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 );
                     m_board->m_Modules->Add( item );
@@ -579,7 +579,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 );