← Back to team overview

kicad-developers team mailing list archive

Multiple delete in dialog_spice_model.cpp


Hi KiCad-devs & Seth,

I was looking at the code for handling spice fields and I noticed
something that I either don't understand or is unnecessary. In this


there was a change added in dialog_spice_model.cpp:241-246, which is
present in current master branch. This is how it looks right now:

    // Apply the settings
    for( int i = 0; i < SF_END; ++i )
        if( m_fieldsTmp.count( (SPICE_FIELD) i ) > 0 && !m_fieldsTmp.at( i ).IsEmpty() )
            if( m_useSchFields )
                getSchField( i ).SetText( m_fieldsTmp[i] );
                getLibField( i ).SetText( m_fieldsTmp[i] );
            // Erase empty fields (having empty fields causes a warning in the properties dialog)
            const wxString& spiceField = NETLIST_EXPORTER_PSPICE::GetSpiceFieldName( (SPICE_FIELD) i );

            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() );
                m_libfields->erase( std::remove_if( m_libfields->begin(), m_libfields->end(),
                        [&]( const LIB_FIELD& f ) { return f.GetName() == spiceField; } ), m_libfields->end() );

In this loop we iterate over all available SPICE fields while m_fieldsTmp contain new values to be stored. 
If m_fieldsTmp is non-empty, we add a new value to the field. If it's empty, we will delete this field. 

My question is, why deletion is repeated: at first there is called remove_if(), and later erase(), which will delete
all the fields behind the removed one. From my point of view it looks like remove_if() only should be enough. 

Best regards,

Follow ups