Lunchbox  1.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
algorithm.h
1 
2 /* Copyright (c) 2013, Stefan.Eilemann@epfl.ch
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #ifndef LUNCHBOX_ALGORITHM_H
19 #define LUNCHBOX_ALGORITHM_H
20 
21 #include <lunchbox/compiler.h>
22 #include <algorithm>
23 #include <vector>
24 
25 #ifdef LB_GCC_4_4_OR_LATER
26 # include <parallel/algorithm>
27 #endif
28 
29 namespace lunchbox
30 {
32 #ifdef LB_GCC_4_4_OR_LATER
33 using std::__parallel::sort;
34 #else
35 using std::sort;
36 #endif
37 
39 template< typename T > typename std::vector< T >::iterator
40 find( std::vector< T >& container, const T& element )
41  { return std::find( container.begin(), container.end(), element ); }
42 
44 template< typename T > typename std::vector< T >::const_iterator
45 find( const std::vector< T >& container, const T& element )
46  { return std::find( container.begin(), container.end(), element ); }
47 
49 template< typename T, typename P > typename std::vector< T >::iterator
50 find_if( std::vector< T >& container, const P& predicate )
51  { return std::find_if( container.begin(), container.end(), predicate );}
52 
54 template< typename T, typename P > typename std::vector<T>::const_iterator
55 find_if( std::vector< const T >& container, const P& predicate )
56  { return std::find_if( container.begin(), container.end(), predicate );}
57 
59 template< typename C > void usort( C& c )
60 {
61  std::sort( c.begin(), c.end( ));
62  c.erase( std::unique( c.begin(), c.end( )), c.end( ));
63 }
64 
65 }
66 
67 #endif // LUNCHBOX_ALGORITHM_H
std::vector< T >::iterator find_if(std::vector< T > &container, const P &predicate)
Find the element matching the predicate.
Definition: algorithm.h:50
std::vector< T >::iterator find(std::vector< T > &container, const T &element)
Find the element in the given vector.
Definition: algorithm.h:40
void usort(C &c)
Uniquely sort and eliminate duplicates in a container.
Definition: algorithm.h:59