1 #ifndef MSP_CORE_ALGORITHM_H_
2 #define MSP_CORE_ALGORITHM_H_
8 template<typename Container, typename T>
9 inline typename Container::iterator find(Container &cont, const T &value)
11 return std::find(cont.begin(), cont.end(), value);
14 template<typename Container, typename T>
15 inline typename Container::const_iterator find(const Container &cont, const T &value)
17 return std::find(cont.begin(), cont.end(), value);
20 template<typename Container, typename Predicate>
21 inline typename Container::iterator find_if(Container &cont, Predicate pred)
23 return std::find_if(cont.begin(), cont.end(), pred);
26 template<typename Container, typename Predicate>
27 inline typename Container::const_iterator find_if(const Container &cont, Predicate pred)
29 return std::find_if(cont.begin(), cont.end(), pred);
32 template<typename Container, typename T>
33 inline typename Container::iterator lower_bound(Container &cont, const T &value)
35 return std::lower_bound(cont.begin(), cont.end(), value);
38 template<typename Container, typename T>
39 inline typename Container::const_iterator lower_bound(const Container &cont, const T &value)
41 return std::lower_bound(cont.begin(), cont.end(), value);
44 template<typename Container, typename T, typename Predicate>
45 inline typename Container::iterator lower_bound(Container &cont, const T &value, Predicate pred)
47 return std::lower_bound(cont.begin(), cont.end(), value, pred);
50 template<typename Container, typename T, typename Predicate>
51 inline typename Container::const_iterator lower_bound(const Container &cont, const T &value, Predicate pred)
53 return std::lower_bound(cont.begin(), cont.end(), value, pred);
56 template<typename Container, typename T>
57 inline typename Container::iterator upper_bound(Container &cont, const T &value)
59 return std::upper_bound(cont.begin(), cont.end(), value);
62 template<typename Container, typename T>
63 inline typename Container::const_iterator upper_bound(const Container &cont, const T &value)
65 return std::upper_bound(cont.begin(), cont.end(), value);
68 template<typename Container, typename T, typename Predicate>
69 inline typename Container::iterator upper_bound(Container &cont, const T &value, Predicate pred)
71 return std::upper_bound(cont.begin(), cont.end(), value, pred);
74 template<typename Container, typename T, typename Predicate>
75 inline typename Container::const_iterator upper_bound(const Container &cont, const T &value, Predicate pred)
77 return std::upper_bound(cont.begin(), cont.end(), value, pred);
80 template<typename Container>
81 inline void sort(Container &cont)
83 std::sort(cont.begin(), cont.end());
86 template<typename Container, typename Predicate>
87 inline void sort(Container &cont, Predicate pred)
89 std::sort(cont.begin(), cont.end(), pred);
92 template<typename Container>
93 inline void stable_sort(Container &cont)
95 std::stable_sort(cont.begin(), cont.end());
98 template<typename Container, typename Predicate>
99 inline void stable_sort(Container &cont, Predicate pred)
101 std::stable_sort(cont.begin(), cont.end(), pred);
104 template<typename C, typename T>
110 MemberMatch(const T &v, T C::*p): value(v), mem_ptr(p) { }
112 bool operator()(const C &obj) { return obj.*mem_ptr==value; }
115 template<typename Container, typename T>
116 inline typename Container::iterator find_member(Container &cont, const T &value, T Container::value_type::*mp)
118 return find_if(cont, MemberMatch<typename Container::value_type, T>(value, mp));
121 template<typename Container, typename T>
122 inline typename Container::const_iterator find_member(const Container &cont, const T &value, T Container::value_type::*mp)
124 return find_if(cont, MemberMatch<typename Container::value_type, T>(value, mp));
127 template<typename C, typename T>
132 MemberCompare(T C::*p): mem_ptr(p) { }
134 bool operator()(const C &obj, const T &v) { return obj.*mem_ptr<v; }
135 bool operator()(const C &obj1, const C &obj2) { return obj1.*mem_ptr<obj2.*mem_ptr; }
138 template<typename Container, typename T>
139 inline typename Container::iterator lower_bound_member(Container &cont, const T &value, T Container::value_type::*mp)
141 return lower_bound(cont, value, MemberCompare<typename Container::value_type, T>(mp));
144 template<typename Container, typename T>
145 inline typename Container::const_iterator lower_bound_member(const Container &cont, const T &value, T Container::value_type::*mp)
147 return lower_bound(cont, value, MemberCompare<typename Container::value_type, T>(mp));
150 template<typename Container, typename T>
151 inline typename Container::iterator upper_bound_member(Container &cont, const T &value, T Container::value_type::*mp)
153 return upper_bound(cont, value, MemberCompare<typename Container::value_type, T>(mp));
156 template<typename Container, typename T>
157 inline typename Container::const_iterator upper_bound_member(const Container &cont, const T &value, T Container::value_type::*mp)
159 return upper_bound(cont, value, MemberCompare<typename Container::value_type, T>(mp));
162 template<typename Container, typename T>
163 inline void sort_member(Container &cont, T Container::value_type::*mp)
165 sort(cont, MemberCompare<typename Container::value_type, T>(mp));
168 template<typename Container, typename T>
169 inline void stable_sort_member(Container &cont, T Container::value_type::*mp)
171 stable_sort(cont, MemberCompare<typename Container::value_type, T>(mp));
174 template<typename Container, typename Predicate>
175 inline void transform(Container &cont, Predicate pred)
177 transform(cont.begin(), cont.end(), cont.begin(), pred);