Lunchbox  1.17.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
algorithm.h
1 
2 /* Copyright (c) 2013-2017, 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 
23 #include <algorithm>
24 #include <vector>
25 #ifdef LB_GCC_4_4_OR_LATER
26 #include <parallel/algorithm>
27 #endif
28 
29 namespace lunchbox
30 {
32 #ifdef LB_USE_STD_PARALLEL
33 using std::__parallel::sort;
34 #else
35 using std::sort;
36 #endif
37 
39 template <typename T>
40 typename std::vector<T>::iterator find(std::vector<T>& container,
41  const T& element)
42 {
43  return std::find(container.begin(), container.end(), element);
44 }
45 
47 template <typename T>
48 typename std::vector<T>::const_iterator find(const std::vector<T>& container,
49  const T& element)
50 {
51  return std::find(container.begin(), container.end(), element);
52 }
53 
55 template <typename T, typename P>
56 typename std::vector<T>::iterator find_if(std::vector<T>& container,
57  const P& predicate)
58 {
59  return std::find_if(container.begin(), container.end(), predicate);
60 }
61 
63 template <typename T, typename P>
64 typename std::vector<T>::const_iterator find_if(std::vector<const T>& container,
65  const P& predicate)
66 {
67  return std::find_if(container.begin(), container.end(), predicate);
68 }
69 
71 template <typename C>
72 void usort(C& c)
73 {
74  std::sort(c.begin(), c.end());
75  c.erase(std::unique(c.begin(), c.end()), c.end());
76 }
77 }
78 
79 #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:56
std::vector< T >::iterator find(std::vector< T > &container, const T &element)
Find the element in the given vector.
Definition: algorithm.h:40
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:29
void usort(C &c)
Uniquely sort and eliminate duplicates in a container.
Definition: algorithm.h:72