]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/detail/algorithm.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
6f8fcda99900f4d56b94aa441f77d4eb796885ee
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / detail / algorithm.hpp
1 // (C) Copyright Jeremy Siek 2001.\r
2 // Distributed under the Boost Software License, Version 1.0. (See accompany-\r
3 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\r
4 \r
5 /*\r
6  *\r
7  * Copyright (c) 1994\r
8  * Hewlett-Packard Company\r
9  *\r
10  * Permission to use, copy, modify, distribute and sell this software\r
11  * and its documentation for any purpose is hereby granted without fee,\r
12  * provided that the above copyright notice appear in all copies and\r
13  * that both that copyright notice and this permission notice appear\r
14  * in supporting documentation.  Hewlett-Packard Company makes no\r
15  * representations about the suitability of this software for any\r
16  * purpose.  It is provided "as is" without express or implied warranty.\r
17  *\r
18  *\r
19  * Copyright (c) 1996\r
20  * Silicon Graphics Computer Systems, Inc.\r
21  *\r
22  * Permission to use, copy, modify, distribute and sell this software\r
23  * and its documentation for any purpose is hereby granted without fee,\r
24  * provided that the above copyright notice appear in all copies and\r
25  * that both that copyright notice and this permission notice appear\r
26  * in supporting documentation.  Silicon Graphics makes no\r
27  * representations about the suitability of this software for any\r
28  * purpose.  It is provided "as is" without express or implied warranty.\r
29  */\r
30 \r
31 #ifndef BOOST_ALGORITHM_HPP\r
32 # define BOOST_ALGORITHM_HPP\r
33 # include <boost/detail/iterator.hpp>\r
34 // Algorithms on sequences\r
35 //\r
36 // The functions in this file have not yet gone through formal\r
37 // review, and are subject to change. This is a work in progress.\r
38 // They have been checked into the detail directory because\r
39 // there are some graph algorithms that use these functions.\r
40 \r
41 #include <algorithm>\r
42 #include <vector>\r
43 \r
44 namespace boost {\r
45 \r
46   template <typename Iter1, typename Iter2>\r
47   Iter1 begin(const std::pair<Iter1, Iter2>& p) { return p.first; }\r
48 \r
49   template <typename Iter1, typename Iter2>\r
50   Iter2 end(const std::pair<Iter1, Iter2>& p) { return p.second; }\r
51 \r
52   template <typename Iter1, typename Iter2>\r
53   typename boost::detail::iterator_traits<Iter1>::difference_type\r
54   size(const std::pair<Iter1, Iter2>& p) {\r
55     return std::distance(p.first, p.second);\r
56   }\r
57 \r
58 #if 0\r
59   // These seem to interfere with the std::pair overloads :(\r
60   template <typename Container>\r
61   typename Container::iterator\r
62   begin(Container& c) { return c.begin(); }\r
63 \r
64   template <typename Container>\r
65   typename Container::const_iterator\r
66   begin(const Container& c) { return c.begin(); }\r
67 \r
68   template <typename Container>\r
69   typename Container::iterator\r
70   end(Container& c) { return c.end(); }\r
71 \r
72   template <typename Container>\r
73   typename Container::const_iterator\r
74   end(const Container& c) { return c.end(); }\r
75 \r
76   template <typename Container>\r
77   typename Container::size_type\r
78   size(const Container& c) { return c.size(); }\r
79 #else\r
80   template <typename T>\r
81   typename std::vector<T>::iterator\r
82   begin(std::vector<T>& c) { return c.begin(); }\r
83 \r
84   template <typename T>\r
85   typename std::vector<T>::const_iterator\r
86   begin(const std::vector<T>& c) { return c.begin(); }\r
87 \r
88   template <typename T>\r
89   typename std::vector<T>::iterator\r
90   end(std::vector<T>& c) { return c.end(); }\r
91 \r
92   template <typename T>\r
93   typename std::vector<T>::const_iterator\r
94   end(const std::vector<T>& c) { return c.end(); }\r
95 \r
96   template <typename T>\r
97   typename std::vector<T>::size_type\r
98   size(const std::vector<T>& c) { return c.size(); }\r
99 #endif\r
100   \r
101   template <class ForwardIterator, class T>\r
102   void iota(ForwardIterator first, ForwardIterator last, T value)\r
103   {\r
104     for (; first != last; ++first, ++value)\r
105       *first = value;\r
106   }\r
107   template <typename Container, typename T>\r
108   void iota(Container& c, const T& value)\r
109   {\r
110     iota(begin(c), end(c), value);\r
111   }\r
112  \r
113   // Also do version with 2nd container?\r
114   template <typename Container, typename OutIter>\r
115   OutIter copy(const Container& c, OutIter result) {\r
116     return std::copy(begin(c), end(c), result);\r
117   }\r
118 \r
119   template <typename Container1, typename Container2>\r
120   bool equal(const Container1& c1, const Container2& c2)\r
121   {\r
122     if (size(c1) != size(c2))\r
123       return false;\r
124     return std::equal(begin(c1), end(c1), begin(c2));\r
125   }\r
126 \r
127   template <typename Container>\r
128   void sort(Container& c) { std::sort(begin(c), end(c)); }\r
129 \r
130   template <typename Container, typename Predicate>\r
131   void sort(Container& c, const Predicate& p) { \r
132     std::sort(begin(c), end(c), p);\r
133   }\r
134 \r
135   template <typename Container>\r
136   void stable_sort(Container& c) { std::stable_sort(begin(c), end(c)); }\r
137 \r
138   template <typename Container, typename Predicate>\r
139   void stable_sort(Container& c, const Predicate& p) { \r
140     std::stable_sort(begin(c), end(c), p);\r
141   }\r
142 \r
143   template <typename InputIterator, typename Predicate>\r
144   bool any_if(InputIterator first, InputIterator last, Predicate p)\r
145   {\r
146     return std::find_if(first, last, p) != last;\r
147   }\r
148   template <typename Container, typename Predicate>\r
149   bool any_if(const Container& c, Predicate p)\r
150   {\r
151     return any_if(begin(c), end(c), p);\r
152   }\r
153 \r
154   template <typename InputIterator, typename T>\r
155   bool container_contains(InputIterator first, InputIterator last, T value)\r
156   {\r
157     return std::find(first, last, value) != last;\r
158   }\r
159   template <typename Container, typename T>\r
160   bool container_contains(const Container& c, const T& value)\r
161   {\r
162     return container_contains(begin(c), end(c), value);\r
163   }\r
164 \r
165   template <typename Container, typename T>\r
166   std::size_t count(const Container& c, const T& value)\r
167   {\r
168     return std::count(begin(c), end(c), value);\r
169   }\r
170 \r
171   template <typename Container, typename Predicate>\r
172   std::size_t count_if(const Container& c, Predicate p)\r
173   {\r
174     return std::count_if(begin(c), end(c), p);\r
175   }\r
176 \r
177   template <typename ForwardIterator>\r
178   bool is_sorted(ForwardIterator first, ForwardIterator last)\r
179   {\r
180     if (first == last)\r
181       return true;\r
182 \r
183     ForwardIterator next = first;\r
184     for (++next; next != last; first = next, ++next) {\r
185       if (*next < *first)\r
186         return false;\r
187     }\r
188 \r
189     return true;\r
190   }\r
191 \r
192   template <typename ForwardIterator, typename StrictWeakOrdering>\r
193   bool is_sorted(ForwardIterator first, ForwardIterator last,\r
194                  StrictWeakOrdering comp)\r
195   {\r
196     if (first == last)\r
197       return true;\r
198 \r
199     ForwardIterator next = first;\r
200     for (++next; next != last; first = next, ++next) {\r
201       if (comp(*next, *first))\r
202         return false;\r
203     }\r
204 \r
205     return true;\r
206   }\r
207 \r
208   template <typename Container>\r
209   bool is_sorted(const Container& c)\r
210   {\r
211     return is_sorted(begin(c), end(c));\r
212   }\r
213 \r
214   template <typename Container, typename StrictWeakOrdering>\r
215   bool is_sorted(const Container& c, StrictWeakOrdering comp)\r
216   {\r
217     return is_sorted(begin(c), end(c), comp);\r
218   }\r
219 \r
220 } // namespace boost\r
221 \r
222 #endif // BOOST_ALGORITHM_HPP\r