/project/jni/stlport/stlport/stl/_algo.h

https://github.com/aichunyu/FFPlayer · C Header · 760 lines · 553 code · 139 blank · 68 comment · 63 complexity · 8361547bf62936dfe3c75760393a8990 MD5 · raw file

  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996,1997
  7. * Silicon Graphics Computer Systems, Inc.
  8. *
  9. * Copyright (c) 1997
  10. * Moscow Center for SPARC Technology
  11. *
  12. * Copyright (c) 1999
  13. * Boris Fomitchev
  14. *
  15. * This material is provided "as is", with absolutely no warranty expressed
  16. * or implied. Any use is at your own risk.
  17. *
  18. * Permission to use or copy this software for any purpose is hereby granted
  19. * without fee, provided the above notices are retained on all copies.
  20. * Permission to modify the code and to distribute modified code is granted,
  21. * provided the above notices are retained, and a notice that the code was
  22. * modified is included with the above copyright notice.
  23. *
  24. */
  25. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_ALGO_H
  29. #define _STLP_INTERNAL_ALGO_H
  30. #ifndef _STLP_INTERNAL_ALGOBASE_H
  31. # include <stl/_algobase.h>
  32. #endif
  33. #ifndef _STLP_INTERNAL_HEAP_H
  34. # include <stl/_heap.h>
  35. #endif
  36. #ifndef _STLP_INTERNAL_ITERATOR_H
  37. # include <stl/_iterator.h>
  38. #endif
  39. #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
  40. # include <stl/_function_base.h>
  41. #endif
  42. #if defined (__SUNPRO_CC) && !defined (_STLP_INTERNAL_CSTDIO)
  43. // remove() conflict
  44. # include <stl/_cstdio.h>
  45. #endif
  46. _STLP_BEGIN_NAMESPACE
  47. // for_each. Apply a function to every element of a range.
  48. template <class _InputIter, class _Function>
  49. _STLP_INLINE_LOOP _Function
  50. for_each(_InputIter __first, _InputIter __last, _Function __f) {
  51. for ( ; __first != __last; ++__first)
  52. __f(*__first);
  53. return __f;
  54. }
  55. // count_if
  56. template <class _InputIter, class _Predicate>
  57. _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
  58. count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
  59. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  60. _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
  61. for ( ; __first != __last; ++__first) {
  62. if (__pred(*__first))
  63. ++__n;
  64. }
  65. return __n;
  66. }
  67. // adjacent_find.
  68. template <class _ForwardIter, class _BinaryPredicate>
  69. _STLP_INLINE_LOOP _ForwardIter
  70. adjacent_find(_ForwardIter __first, _ForwardIter __last,
  71. _BinaryPredicate __binary_pred) {
  72. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  73. if (__first == __last)
  74. return __last;
  75. _ForwardIter __next = __first;
  76. while(++__next != __last) {
  77. if (__binary_pred(*__first, *__next))
  78. return __first;
  79. __first = __next;
  80. }
  81. return __last;
  82. }
  83. template <class _ForwardIter>
  84. _STLP_INLINE_LOOP _ForwardIter
  85. adjacent_find(_ForwardIter __first, _ForwardIter __last) {
  86. return adjacent_find(__first, __last,
  87. _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first, _ForwardIter)));
  88. }
  89. #if !defined (_STLP_NO_ANACHRONISMS)
  90. template <class _InputIter, class _Tp, class _Size>
  91. _STLP_INLINE_LOOP void
  92. count(_InputIter __first, _InputIter __last, const _Tp& __val, _Size& __n) {
  93. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  94. for ( ; __first != __last; ++__first)
  95. if (*__first == __val)
  96. ++__n;
  97. }
  98. template <class _InputIter, class _Predicate, class _Size>
  99. _STLP_INLINE_LOOP void
  100. count_if(_InputIter __first, _InputIter __last, _Predicate __pred, _Size& __n) {
  101. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  102. for ( ; __first != __last; ++__first)
  103. if (__pred(*__first))
  104. ++__n;
  105. }
  106. #endif
  107. template <class _ForwardIter1, class _ForwardIter2>
  108. _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
  109. _ForwardIter2 __first2, _ForwardIter2 __last2);
  110. // search_n. Search for __count consecutive copies of __val.
  111. template <class _ForwardIter, class _Integer, class _Tp>
  112. _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
  113. _Integer __count, const _Tp& __val);
  114. template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
  115. _ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
  116. _Integer __count, const _Tp& __val, _BinaryPred __binary_pred);
  117. template <class _InputIter, class _ForwardIter>
  118. inline _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
  119. _ForwardIter __first2, _ForwardIter __last2) {
  120. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
  121. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
  122. return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2,
  123. _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first1, _InputIter)));
  124. }
  125. template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
  126. inline _InputIter
  127. find_first_of(_InputIter __first1, _InputIter __last1,
  128. _ForwardIter __first2, _ForwardIter __last2, _BinaryPredicate __comp) {
  129. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
  130. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
  131. return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2, __comp);
  132. }
  133. template <class _ForwardIter1, class _ForwardIter2>
  134. _ForwardIter1
  135. find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
  136. _ForwardIter2 __first2, _ForwardIter2 __last2);
  137. // swap_ranges
  138. template <class _ForwardIter1, class _ForwardIter2>
  139. _STLP_INLINE_LOOP _ForwardIter2
  140. swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2) {
  141. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
  142. for ( ; __first1 != __last1; ++__first1, ++__first2)
  143. iter_swap(__first1, __first2);
  144. return __first2;
  145. }
  146. // transform
  147. template <class _InputIter, class _OutputIter, class _UnaryOperation>
  148. _STLP_INLINE_LOOP _OutputIter
  149. transform(_InputIter __first, _InputIter __last, _OutputIter __result, _UnaryOperation __opr) {
  150. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  151. for ( ; __first != __last; ++__first, ++__result)
  152. *__result = __opr(*__first);
  153. return __result;
  154. }
  155. template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>
  156. _STLP_INLINE_LOOP _OutputIter
  157. transform(_InputIter1 __first1, _InputIter1 __last1,
  158. _InputIter2 __first2, _OutputIter __result,_BinaryOperation __binary_op) {
  159. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
  160. for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
  161. *__result = __binary_op(*__first1, *__first2);
  162. return __result;
  163. }
  164. // replace_if, replace_copy, replace_copy_if
  165. template <class _ForwardIter, class _Predicate, class _Tp>
  166. _STLP_INLINE_LOOP void
  167. replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp& __new_value) {
  168. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  169. for ( ; __first != __last; ++__first)
  170. if (__pred(*__first))
  171. *__first = __new_value;
  172. }
  173. template <class _InputIter, class _OutputIter, class _Tp>
  174. _STLP_INLINE_LOOP _OutputIter
  175. replace_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
  176. const _Tp& __old_value, const _Tp& __new_value) {
  177. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  178. for ( ; __first != __last; ++__first, ++__result)
  179. *__result = *__first == __old_value ? __new_value : *__first;
  180. return __result;
  181. }
  182. template <class _Iterator, class _OutputIter, class _Predicate, class _Tp>
  183. _STLP_INLINE_LOOP _OutputIter
  184. replace_copy_if(_Iterator __first, _Iterator __last,
  185. _OutputIter __result,
  186. _Predicate __pred, const _Tp& __new_value) {
  187. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  188. for ( ; __first != __last; ++__first, ++__result)
  189. *__result = __pred(*__first) ? __new_value : *__first;
  190. return __result;
  191. }
  192. // generate and generate_n
  193. template <class _ForwardIter, class _Generator>
  194. _STLP_INLINE_LOOP void
  195. generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
  196. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  197. for ( ; __first != __last; ++__first)
  198. *__first = __gen();
  199. }
  200. template <class _OutputIter, class _Size, class _Generator>
  201. _STLP_INLINE_LOOP void
  202. generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
  203. for ( ; __n > 0; --__n, ++__first)
  204. *__first = __gen();
  205. }
  206. // remove, remove_if, remove_copy, remove_copy_if
  207. template <class _InputIter, class _OutputIter, class _Tp>
  208. _STLP_INLINE_LOOP _OutputIter
  209. remove_copy(_InputIter __first, _InputIter __last,_OutputIter __result, const _Tp& __val) {
  210. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  211. for ( ; __first != __last; ++__first) {
  212. if (!(*__first == __val)) {
  213. *__result = *__first;
  214. ++__result;
  215. }
  216. }
  217. return __result;
  218. }
  219. template <class _InputIter, class _OutputIter, class _Predicate>
  220. _STLP_INLINE_LOOP _OutputIter
  221. remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter __result, _Predicate __pred) {
  222. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  223. for ( ; __first != __last; ++__first) {
  224. if (!__pred(*__first)) {
  225. *__result = *__first;
  226. ++__result;
  227. }
  228. }
  229. return __result;
  230. }
  231. template <class _ForwardIter, class _Tp>
  232. _STLP_INLINE_LOOP _ForwardIter
  233. remove(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
  234. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  235. __first = find(__first, __last, __val);
  236. if (__first == __last)
  237. return __first;
  238. else {
  239. _ForwardIter __next = __first;
  240. return remove_copy(++__next, __last, __first, __val);
  241. }
  242. }
  243. template <class _ForwardIter, class _Predicate>
  244. _STLP_INLINE_LOOP _ForwardIter
  245. remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred) {
  246. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  247. __first = find_if(__first, __last, __pred);
  248. if ( __first == __last )
  249. return __first;
  250. else {
  251. _ForwardIter __next = __first;
  252. return remove_copy_if(++__next, __last, __first, __pred);
  253. }
  254. }
  255. // unique and unique_copy
  256. template <class _InputIter, class _OutputIter>
  257. _OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result);
  258. template <class _InputIter, class _OutputIter, class _BinaryPredicate>
  259. _OutputIter unique_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
  260. _BinaryPredicate __binary_pred);
  261. template <class _ForwardIter>
  262. inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
  263. __first = adjacent_find(__first, __last);
  264. return unique_copy(__first, __last, __first);
  265. }
  266. template <class _ForwardIter, class _BinaryPredicate>
  267. inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
  268. _BinaryPredicate __binary_pred) {
  269. __first = adjacent_find(__first, __last, __binary_pred);
  270. return unique_copy(__first, __last, __first, __binary_pred);
  271. }
  272. // reverse and reverse_copy, and their auxiliary functions
  273. template <class _BidirectionalIter>
  274. _STLP_INLINE_LOOP void
  275. __reverse(_BidirectionalIter __first, _BidirectionalIter __last, const bidirectional_iterator_tag &) {
  276. for (; __first != __last && __first != --__last; ++__first)
  277. iter_swap(__first,__last);
  278. }
  279. template <class _RandomAccessIter>
  280. _STLP_INLINE_LOOP void
  281. __reverse(_RandomAccessIter __first, _RandomAccessIter __last, const random_access_iterator_tag &) {
  282. for (; __first < __last; ++__first)
  283. iter_swap(__first, --__last);
  284. }
  285. template <class _BidirectionalIter>
  286. inline void
  287. reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
  288. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  289. __reverse(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _BidirectionalIter));
  290. }
  291. template <class _BidirectionalIter, class _OutputIter>
  292. _STLP_INLINE_LOOP
  293. _OutputIter reverse_copy(_BidirectionalIter __first,
  294. _BidirectionalIter __last,
  295. _OutputIter __result) {
  296. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  297. while (__first != __last) {
  298. --__last;
  299. *__result = *__last;
  300. ++__result;
  301. }
  302. return __result;
  303. }
  304. _STLP_MOVE_TO_PRIV_NAMESPACE
  305. // rotate and rotate_copy, and their auxiliary functions
  306. template <class _EuclideanRingElement>
  307. _STLP_INLINE_LOOP
  308. _EuclideanRingElement __gcd(_EuclideanRingElement __m,
  309. _EuclideanRingElement __n) {
  310. while (__n != 0) {
  311. _EuclideanRingElement __t = __m % __n;
  312. __m = __n;
  313. __n = __t;
  314. }
  315. return __m;
  316. }
  317. _STLP_MOVE_TO_STD_NAMESPACE
  318. template <class _ForwardIter>
  319. void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last);
  320. template <class _ForwardIter, class _OutputIter>
  321. inline _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
  322. _ForwardIter __last, _OutputIter __result) {
  323. return copy(__first, __middle, copy(__middle, __last, __result));
  324. }
  325. // random_shuffle
  326. template <class _RandomAccessIter>
  327. void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last);
  328. template <class _RandomAccessIter, class _RandomNumberGenerator>
  329. void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
  330. _RandomNumberGenerator& __rand);
  331. #if !defined (_STLP_NO_EXTENSIONS)
  332. // random_sample and random_sample_n (extensions, not part of the standard).
  333. template <class _ForwardIter, class _OutputIter, class _Distance>
  334. _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
  335. _OutputIter __out_ite, const _Distance __n);
  336. template <class _ForwardIter, class _OutputIter, class _Distance,
  337. class _RandomNumberGenerator>
  338. _OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
  339. _OutputIter __out_ite, const _Distance __n,
  340. _RandomNumberGenerator& __rand);
  341. template <class _InputIter, class _RandomAccessIter>
  342. _RandomAccessIter
  343. random_sample(_InputIter __first, _InputIter __last,
  344. _RandomAccessIter __out_first, _RandomAccessIter __out_last);
  345. template <class _InputIter, class _RandomAccessIter,
  346. class _RandomNumberGenerator>
  347. _RandomAccessIter
  348. random_sample(_InputIter __first, _InputIter __last,
  349. _RandomAccessIter __out_first, _RandomAccessIter __out_last,
  350. _RandomNumberGenerator& __rand);
  351. #endif /* _STLP_NO_EXTENSIONS */
  352. // partition, stable_partition, and their auxiliary functions
  353. template <class _ForwardIter, class _Predicate>
  354. _ForwardIter partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
  355. template <class _ForwardIter, class _Predicate>
  356. _ForwardIter
  357. stable_partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
  358. // sort() and its auxiliary functions.
  359. _STLP_MOVE_TO_PRIV_NAMESPACE
  360. template <class _Size>
  361. inline _Size __lg(_Size __n) {
  362. _Size __k;
  363. for (__k = 0; __n != 1; __n >>= 1) ++__k;
  364. return __k;
  365. }
  366. _STLP_MOVE_TO_STD_NAMESPACE
  367. template <class _RandomAccessIter>
  368. void sort(_RandomAccessIter __first, _RandomAccessIter __last);
  369. template <class _RandomAccessIter, class _Compare>
  370. void sort(_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp);
  371. // stable_sort() and its auxiliary functions.
  372. template <class _RandomAccessIter>
  373. void stable_sort(_RandomAccessIter __first,
  374. _RandomAccessIter __last);
  375. template <class _RandomAccessIter, class _Compare>
  376. void stable_sort(_RandomAccessIter __first,
  377. _RandomAccessIter __last, _Compare __comp);
  378. // partial_sort, partial_sort_copy, and auxiliary functions.
  379. template <class _RandomAccessIter>
  380. void partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
  381. _RandomAccessIter __last);
  382. template <class _RandomAccessIter, class _Compare>
  383. void partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle,
  384. _RandomAccessIter __last, _Compare __comp);
  385. template <class _InputIter, class _RandomAccessIter>
  386. _RandomAccessIter
  387. partial_sort_copy(_InputIter __first, _InputIter __last,
  388. _RandomAccessIter __result_first, _RandomAccessIter __result_last);
  389. template <class _InputIter, class _RandomAccessIter, class _Compare>
  390. _RandomAccessIter
  391. partial_sort_copy(_InputIter __first, _InputIter __last,
  392. _RandomAccessIter __result_first,
  393. _RandomAccessIter __result_last, _Compare __comp);
  394. // nth_element() and its auxiliary functions.
  395. template <class _RandomAccessIter>
  396. void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
  397. _RandomAccessIter __last);
  398. template <class _RandomAccessIter, class _Compare>
  399. void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
  400. _RandomAccessIter __last, _Compare __comp);
  401. // auxiliary class for lower_bound, etc.
  402. _STLP_MOVE_TO_PRIV_NAMESPACE
  403. template <class _T1, class _T2>
  404. struct __less_2 {
  405. bool operator() (const _T1& __x, const _T2& __y) const { return __x < __y ; }
  406. };
  407. template <class _T1, class _T2>
  408. __less_2<_T1,_T2> __less2(_T1*, _T2* ) { return __less_2<_T1, _T2>(); }
  409. #if defined (_STLP_FUNCTION_PARTIAL_ORDER)
  410. template <class _Tp>
  411. less<_Tp> __less2(_Tp*, _Tp* ) { return less<_Tp>(); }
  412. #endif
  413. _STLP_MOVE_TO_STD_NAMESPACE
  414. // Binary search (lower_bound, upper_bound, equal_range, binary_search).
  415. template <class _ForwardIter, class _Tp>
  416. inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
  417. const _Tp& __val) {
  418. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  419. return _STLP_PRIV __lower_bound(__first, __last, __val,
  420. _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
  421. _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
  422. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  423. }
  424. template <class _ForwardIter, class _Tp, class _Compare>
  425. inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
  426. const _Tp& __val, _Compare __comp) {
  427. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  428. return _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
  429. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  430. }
  431. _STLP_MOVE_TO_PRIV_NAMESPACE
  432. template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
  433. _ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
  434. _Compare1 __comp1, _Compare2 __comp2, _Distance*);
  435. _STLP_MOVE_TO_STD_NAMESPACE
  436. template <class _ForwardIter, class _Tp>
  437. inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
  438. const _Tp& __val) {
  439. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  440. return _STLP_PRIV __upper_bound(__first, __last, __val,
  441. _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
  442. _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
  443. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  444. }
  445. template <class _ForwardIter, class _Tp, class _Compare>
  446. inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
  447. const _Tp& __val, _Compare __comp) {
  448. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  449. return _STLP_PRIV __upper_bound(__first, __last, __val, __comp, __comp,
  450. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  451. }
  452. _STLP_MOVE_TO_PRIV_NAMESPACE
  453. template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
  454. pair<_ForwardIter, _ForwardIter>
  455. __equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
  456. _Compare1 __comp1, _Compare2 __comp2, _Distance*);
  457. _STLP_MOVE_TO_STD_NAMESPACE
  458. template <class _ForwardIter, class _Tp>
  459. inline pair<_ForwardIter, _ForwardIter>
  460. equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
  461. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  462. return _STLP_PRIV __equal_range(__first, __last, __val,
  463. _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
  464. _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
  465. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  466. }
  467. template <class _ForwardIter, class _Tp, class _Compare>
  468. inline pair<_ForwardIter, _ForwardIter>
  469. equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
  470. _Compare __comp) {
  471. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  472. return _STLP_PRIV __equal_range(__first, __last, __val, __comp, __comp,
  473. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  474. }
  475. template <class _ForwardIter, class _Tp>
  476. inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
  477. const _Tp& __val) {
  478. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  479. _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val,
  480. _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
  481. _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
  482. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  483. return __i != __last && !(__val < *__i);
  484. }
  485. template <class _ForwardIter, class _Tp, class _Compare>
  486. inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
  487. const _Tp& __val,
  488. _Compare __comp) {
  489. _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
  490. _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
  491. _STLP_DISTANCE_TYPE(__first, _ForwardIter));
  492. return __i != __last && !__comp(__val, *__i);
  493. }
  494. // merge, with and without an explicitly supplied comparison function.
  495. template <class _InputIter1, class _InputIter2, class _OutputIter>
  496. _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
  497. _InputIter2 __first2, _InputIter2 __last2,
  498. _OutputIter __result);
  499. template <class _InputIter1, class _InputIter2, class _OutputIter,
  500. class _Compare>
  501. _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
  502. _InputIter2 __first2, _InputIter2 __last2,
  503. _OutputIter __result, _Compare __comp);
  504. // inplace_merge and its auxiliary functions.
  505. template <class _BidirectionalIter>
  506. void inplace_merge(_BidirectionalIter __first,
  507. _BidirectionalIter __middle,
  508. _BidirectionalIter __last) ;
  509. template <class _BidirectionalIter, class _Compare>
  510. void inplace_merge(_BidirectionalIter __first,
  511. _BidirectionalIter __middle,
  512. _BidirectionalIter __last, _Compare __comp);
  513. // Set algorithms: includes, set_union, set_intersection, set_difference,
  514. // set_symmetric_difference. All of these algorithms have the precondition
  515. // that their input ranges are sorted and the postcondition that their output
  516. // ranges are sorted.
  517. template <class _InputIter1, class _InputIter2>
  518. bool includes(_InputIter1 __first1, _InputIter1 __last1,
  519. _InputIter2 __first2, _InputIter2 __last2);
  520. template <class _InputIter1, class _InputIter2, class _Compare>
  521. bool includes(_InputIter1 __first1, _InputIter1 __last1,
  522. _InputIter2 __first2, _InputIter2 __last2, _Compare __comp);
  523. template <class _InputIter1, class _InputIter2, class _OutputIter>
  524. _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
  525. _InputIter2 __first2, _InputIter2 __last2,
  526. _OutputIter __result);
  527. template <class _InputIter1, class _InputIter2, class _OutputIter,
  528. class _Compare>
  529. _OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
  530. _InputIter2 __first2, _InputIter2 __last2,
  531. _OutputIter __result, _Compare __comp);
  532. template <class _InputIter1, class _InputIter2, class _OutputIter>
  533. _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
  534. _InputIter2 __first2, _InputIter2 __last2,
  535. _OutputIter __result);
  536. template <class _InputIter1, class _InputIter2, class _OutputIter,
  537. class _Compare>
  538. _OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
  539. _InputIter2 __first2, _InputIter2 __last2,
  540. _OutputIter __result, _Compare __comp);
  541. template <class _InputIter1, class _InputIter2, class _OutputIter>
  542. _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
  543. _InputIter2 __first2, _InputIter2 __last2,
  544. _OutputIter __result);
  545. template <class _InputIter1, class _InputIter2, class _OutputIter,
  546. class _Compare>
  547. _OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
  548. _InputIter2 __first2, _InputIter2 __last2,
  549. _OutputIter __result, _Compare __comp);
  550. template <class _InputIter1, class _InputIter2, class _OutputIter>
  551. _OutputIter
  552. set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
  553. _InputIter2 __first2, _InputIter2 __last2,
  554. _OutputIter __result);
  555. template <class _InputIter1, class _InputIter2, class _OutputIter,
  556. class _Compare>
  557. _OutputIter
  558. set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
  559. _InputIter2 __first2, _InputIter2 __last2,
  560. _OutputIter __result,
  561. _Compare __comp);
  562. // min_element and max_element, with and without an explicitly supplied
  563. // comparison function.
  564. template <class _ForwardIter>
  565. _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last);
  566. template <class _ForwardIter, class _Compare>
  567. _ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
  568. _Compare __comp);
  569. template <class _ForwardIter>
  570. _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last);
  571. template <class _ForwardIter, class _Compare>
  572. _ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
  573. _Compare __comp);
  574. // next_permutation and prev_permutation, with and without an explicitly
  575. // supplied comparison function.
  576. template <class _BidirectionalIter>
  577. bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
  578. template <class _BidirectionalIter, class _Compare>
  579. bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
  580. _Compare __comp);
  581. template <class _BidirectionalIter>
  582. bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
  583. template <class _BidirectionalIter, class _Compare>
  584. bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
  585. _Compare __comp);
  586. #if !defined (_STLP_NO_EXTENSIONS)
  587. // is_heap, a predicate testing whether or not a range is
  588. // a heap. This function is an extension, not part of the C++
  589. // standard.
  590. template <class _RandomAccessIter>
  591. bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last);
  592. template <class _RandomAccessIter, class _StrictWeakOrdering>
  593. bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
  594. _StrictWeakOrdering __comp);
  595. // is_sorted, a predicated testing whether a range is sorted in
  596. // nondescending order. This is an extension, not part of the C++
  597. // standard.
  598. _STLP_MOVE_TO_PRIV_NAMESPACE
  599. template <class _ForwardIter, class _StrictWeakOrdering>
  600. bool __is_sorted(_ForwardIter __first, _ForwardIter __last,
  601. _StrictWeakOrdering __comp);
  602. _STLP_MOVE_TO_STD_NAMESPACE
  603. template <class _ForwardIter>
  604. inline bool is_sorted(_ForwardIter __first, _ForwardIter __last) {
  605. return _STLP_PRIV __is_sorted(__first, __last,
  606. _STLP_PRIV __less(_STLP_VALUE_TYPE(__first, _ForwardIter)));
  607. }
  608. template <class _ForwardIter, class _StrictWeakOrdering>
  609. inline bool is_sorted(_ForwardIter __first, _ForwardIter __last,
  610. _StrictWeakOrdering __comp) {
  611. return _STLP_PRIV __is_sorted(__first, __last, __comp);
  612. }
  613. #endif
  614. _STLP_END_NAMESPACE
  615. #if !defined (_STLP_LINK_TIME_INSTANTIATION)
  616. # include <stl/_algo.c>
  617. #endif
  618. #endif /* _STLP_INTERNAL_ALGO_H */
  619. // Local Variables:
  620. // mode:C++
  621. // End: