Lunchbox  1.12.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
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 #ifndef __MINGW32__ // MinGW does not provide the header
26 # ifdef LB_GCC_4_4_OR_LATER
27 # include <parallel/algorithm>
28 # define LB_USE_STD_PARALLEL
29 # endif
30 #endif
31 
32 namespace lunchbox
33 {
35 #ifdef LB_USE_STD_PARALLEL
36 using std::__parallel::sort;
37 #else
38 using std::sort;
39 #endif
40 
42 template< typename T > typename std::vector< T >::iterator
43 find( std::vector< T >& container, const T& element )
44  { return std::find( container.begin(), container.end(), element ); }
45 
47 template< typename T > typename std::vector< T >::const_iterator
48 find( const std::vector< T >& container, const T& element )
49  { return std::find( container.begin(), container.end(), element ); }
50 
52 template< typename T, typename P > typename std::vector< T >::iterator
53 find_if( std::vector< T >& container, const P& predicate )
54  { return std::find_if( container.begin(), container.end(), predicate );}
55 
57 template< typename T, typename P > typename std::vector<T>::const_iterator
58 find_if( std::vector< const T >& container, const P& predicate )
59  { return std::find_if( container.begin(), container.end(), predicate );}
60 
62 template< typename C > void usort( C& c )
63 {
64  std::sort( c.begin(), c.end( ));
65  c.erase( std::unique( c.begin(), c.end( )), c.end( ));
66 }
67 
68 }
69 
70 #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:53
std::vector< T >::iterator find(std::vector< T > &container, const T &element)
Find the element in the given vector.
Definition: algorithm.h:43
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
void usort(C &c)
Uniquely sort and eliminate duplicates in a container.
Definition: algorithm.h:62