KiCad PCB EDA Suite
kicad_algo.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef INCLUDE_CORE_KICAD_ALGO_H_
26 #define INCLUDE_CORE_KICAD_ALGO_H_
27 
28 #include <algorithm>
29 
30 namespace alg
31 {
42 template <typename _InputIterator, typename _Function>
43 void adjacent_pairs( _InputIterator __first, _InputIterator __last, _Function __f )
44 {
45  if( __first != __last )
46  {
47  _InputIterator __follow = __first;
48  ++__first;
49  for( ; __first != __last; ++__first, ++__follow )
50  __f( *__follow, *__first );
51  }
52 }
53 
64 template <typename _InputIterator, typename _Function>
65 void for_all_pairs( _InputIterator __first, _InputIterator __last, _Function __f )
66 {
67  if( __first != __last )
68  {
69  _InputIterator __follow = __first;
70  ++__first;
71  for( ; __first != __last; ++__first, ++__follow )
72  for( _InputIterator __it = __first; __it != __last; ++__it )
73  __f( *__follow, *__it );
74  }
75 }
76 
80 template <class _Container, typename _Value>
81 bool contains( const _Container& __container, _Value __value )
82 {
83  return std::find( __container.begin(), __container.end(), __value ) != __container.end();
84 }
85 } // namespace alg
86 
87 #endif /* INCLUDE_CORE_KICAD_ALGO_H_ */
void for_all_pairs(_InputIterator __first, _InputIterator __last, _Function __f)
Apply a function to every possible pair of elements of a sequence.
Definition: kicad_algo.h:65
Definition: kicad_algo.h:30
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:81
void adjacent_pairs(_InputIterator __first, _InputIterator __last, _Function __f)
Apply a function to every sequential pair of elements of a sequence.
Definition: kicad_algo.h:43