7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 11:50:10 +00:00

Move std::contains to alg::contains.

This commit is contained in:
Jeff Young 2020-09-26 14:42:40 +01:00
parent 1844e8e0df
commit f8875bc5a6
16 changed files with 27 additions and 28 deletions

View File

@ -1037,7 +1037,7 @@ bool TOOL_MANAGER::isActive( TOOL_BASE* aTool )
return false;
// Just check if the tool is on the active tools stack
return std::contains( m_activeTools, aTool->GetId() );
return alg::contains( m_activeTools, aTool->GetId() );
}

View File

@ -36,5 +36,5 @@ BUS_ALIAS::~BUS_ALIAS()
bool BUS_ALIAS::Contains( const wxString& aName )
{
return std::contains( m_members, aName );
return alg::contains( m_members, aName );
}

View File

@ -180,7 +180,7 @@ void DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable( REPORTER& aReporter )
libName.Replace( " ", "-" );
// Don't create duplicate table entries.
while( std::contains( libNames, libName ) )
while( alg::contains( libNames, libName ) )
{
libName = libName.Left( libNameLen );
libName << libNameInc;

View File

@ -1001,7 +1001,7 @@ void LIB_EDIT_FRAME::HardRedraw()
for( LIB_ITEM& item : m_my_part->GetDrawItems() )
{
if( !std::contains( selection, &item ) )
if( !alg::contains( selection, &item ) )
item.ClearSelected();
else
item.SetSelected();

View File

@ -49,6 +49,7 @@
#include <type_traits>
#include <typeinfo>
#include <boost/uuid/uuid.hpp>
#include <core/kicad_algo.h>
#include <macros.h>
class PROJECT;
@ -409,19 +410,6 @@ std::ostream& operator<<( std::ostream& out, const wxSize& size );
std::ostream& operator<<( std::ostream& out, const wxPoint& pt );
#ifndef __cpp_concepts // a proxy for C++20 as there's no __cpp_contains macro
// TODO: remove this once we move to C++20.
namespace std
{
template<class Container, class Value>
bool contains( Container aContainer, Value aValue )
{
return std::find( aContainer.begin(), aContainer.end(), aValue ) != aContainer.end();
}
}
#endif
/**
* A wrapper around a wxFileName which is much more performant with a subset of the API.
*/

View File

@ -25,6 +25,8 @@
#ifndef INCLUDE_CORE_KICAD_ALGO_H_
#define INCLUDE_CORE_KICAD_ALGO_H_
#include <algorithm>
namespace alg
{
/**
@ -71,6 +73,15 @@ void for_all_pairs( _InputIterator __first, _InputIterator __last, _Function __f
__f( *__follow, *__it );
}
}
/**
* @brief Returns true if the container contains the given value.
*/
template <class _Container, typename _Value>
bool contains( _Container __container, _Value __value )
{
return std::find( __container.begin(), __container.end(), __value ) != __container.end();
}
} // namespace alg
#endif /* INCLUDE_CORE_KICAD_ALGO_H_ */

View File

@ -1912,7 +1912,7 @@ void BOARD::SanitizeNetcodes()
void BOARD::AddListener( BOARD_LISTENER* aListener )
{
if( !std::contains( m_listeners, aListener ) )
if( !alg::contains( m_listeners, aListener ) )
m_listeners.push_back( aListener );
}

View File

@ -432,7 +432,7 @@ wxString CN_CLUSTER::OriginNetName() const
bool CN_CLUSTER::Contains( const CN_ITEM* aItem )
{
return std::contains( m_items, aItem );
return alg::contains( m_items, aItem );
}

View File

@ -163,7 +163,7 @@ void DIALOG_EXPORT_SVG::initDialog()
m_boxSelectLayer[layer] = std::make_pair( m_TechnicalLayersList, checkIndex );
}
if( std::contains( cfg->m_ExportSvg.layers, layer ) )
if( alg::contains( cfg->m_ExportSvg.layers, layer ) )
m_boxSelectLayer[layer].first->Check( checkIndex, true );
}
}

View File

@ -754,7 +754,7 @@ LSEQ PANEL_SETUP_LAYERS::getRemovedLayersWithItems()
for( PCB_LAYER_ID layer_id : curLayers.Seq() )
{
if( !std::contains( newLayerSeq, layer_id ) )
if( !alg::contains( newLayerSeq, layer_id ) )
{
collector.SetLayerId( layer_id );
collector.Collect( m_pcb, GENERAL_COLLECTOR::BoardLevelItems );
@ -786,7 +786,7 @@ LSEQ PANEL_SETUP_LAYERS::getNonRemovableLayers()
if( IsCopperLayer( layer_id ) ) // Copper layers are not taken into account here
continue;
if( !std::contains( newLayerSeq, layer_id ) )
if( !alg::contains( newLayerSeq, layer_id ) )
{
collector.SetLayerId( layer_id );
collector.Collect( m_pcb, GENERAL_COLLECTOR::ModuleItems );

View File

@ -40,7 +40,7 @@ GRAPHICS_IMPORT_MGR::GRAPHICS_IMPORT_MGR( const TYPE_LIST& aBlacklist )
std::copy_if( all_types.begin(), all_types.end(), std::back_inserter( m_importableTypes ),
[&aBlacklist]( const GFX_FILE_T& arg )
{
return !std::contains( aBlacklist, arg );
return !alg::contains( aBlacklist, arg );
} );
}

View File

@ -193,7 +193,7 @@ public:
bool Contains( ITEM* aItem ) const
{
const ENTRY ent( aItem );
return std::contains( m_items, ent );
return alg::contains( m_items, ent );
}
void Erase( ITEM* aItem )

View File

@ -56,7 +56,7 @@ public:
///> Checks if the segment aLink is a part of the line.
bool ContainsLink( const LINKED_ITEM* aItem ) const
{
return std::contains( m_links, aItem );
return alg::contains( m_links, aItem );
}
LINKED_ITEM* GetLink( int aIndex ) const

View File

@ -138,7 +138,7 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, int aNet, int aLayer, b
if( !m_iface->IsAnyLayerVisible( item->Layers() ) )
continue;
if( std::contains( aAvoidItems, item ) )
if( alg::contains( aAvoidItems, item ) )
continue;
// fixme: this causes flicker with live loop removal...

View File

@ -872,7 +872,7 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsN
// object.
item->SetSelected();
if( !item->GetParentGroup() || !std::contains( aItems, item->GetParentGroup() ) )
if( !item->GetParentGroup() || !alg::contains( aItems, item->GetParentGroup() ) )
selection.Add( item );
}

View File

@ -1183,7 +1183,7 @@ void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetPath )
{
for( BOARD_CONNECTED_ITEM* mitem : board()->GetConnectivity()->GetNetItems( netCode, padType ) )
{
if( mitem->Type() == PCB_PAD_T && !std::contains( modList, mitem->GetParent() ) )
if( mitem->Type() == PCB_PAD_T && !alg::contains( modList, mitem->GetParent() ) )
{
// if we cannot find the module of the pad in the modList
// then we can assume that that module is not located in the same