25 #ifndef INCLUDE_CORE_KICAD_ALGO_H_
26 #define INCLUDE_CORE_KICAD_ALGO_H_
31 #include "../wx_compat.h"
43 template <
typename _Type,
typename _Function>
44 void run_on_pair( std::pair<_Type, _Type>& __pair, _Function __f )
60 template <
typename _InputIterator,
typename _Function>
61 void adjacent_pairs( _InputIterator __first, _InputIterator __last, _Function __f )
63 if( __first != __last )
65 _InputIterator __follow = __first;
67 for( ; __first != __last; ++__first, ++__follow )
68 __f( *__follow, *__first );
82 template <
typename _InputIterator,
typename _Function>
83 void for_all_pairs( _InputIterator __first, _InputIterator __last, _Function __f )
85 if( __first != __last )
87 _InputIterator __follow = __first;
89 for( ; __first != __last; ++__first, ++__follow )
90 for( _InputIterator __it = __first; __it != __last; ++__it )
91 __f( *__follow, *__it );
98 template <
class _Container,
typename _Value>
99 bool contains(
const _Container& __container, _Value __value )
101 return std::find( __container.begin(), __container.end(), __value ) != __container.end();
111 template <
typename _Type,
typename _Value>
112 bool pair_contains(
const std::pair<_Type, _Type> __pair, _Value __value )
114 return __pair.first ==
static_cast<_Type
>( __value )
115 || __pair.second ==
static_cast<_Type
>( __value );
128 bool within_wrapped_range( T __val, T __minval, T __maxval, T __wrap )
132 while( __maxval >= __wrap )
135 while( __maxval < 0 )
138 while( __minval >= __wrap )
141 while( __minval < 0 )
147 while( __val >= __wrap )
150 if( __maxval > __minval )
151 return __val >= __minval && __val <= __maxval;
153 return __val >= __minval || __val <= __maxval;
163 template <
class _Container,
typename _Value>
164 void delete_matching( _Container& __c, _Value __value )
166 __c.erase( std::remove( __c.begin(), __c.end(), __value ), __c.end() );
172 template <
class _Container,
class _Function>
173 void delete_if( _Container& __c, _Function&& __f )
175 __c.erase( std::remove_if( __c.begin(), __c.end(), std::forward<_Function>( __f ) ), __c.end() );
drop< L, min< find_index< L, T >, size< L > >> find
Return the tail of the list L starting at the first occurrence of T, if any such element exists; the ...
Definition: meta.hpp:2388