?? stl_algo.h
字號:
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef __SGI_STL_INTERNAL_ALGO_H
#define __SGI_STL_INTERNAL_ALGO_H
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1209
#endif
# ifndef __SGI_STL_INTERNAL_ALGOBASE_H
# include <stl_algobase.h>
# endif
# ifndef __SGI_STL_INTERNAL_TEMPBUF_H
# include <stl_tempbuf.h>
# endif
# ifndef __SGI_STL_INTERNAL_HEAP_H
# include <stl_heap.h>
# endif
# ifndef __SGI_STL_INTERNAL_ITERATOR_H
# include <stl_iterator.h>
# endif
__STL_BEGIN_NAMESPACE
// for_each. Apply a function to every element of a range.
template <class _InputIter, class _Function>
_Function for_each(_InputIter __first, _InputIter __last, _Function __f);
// find and find_if.
template <class _InputIter, class _Tp>
inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val,
input_iterator_tag)
{
__stl_debug_check(__check_range(__first, __last));
while (__first != __last && *__first != __val)
++__first;
return __first;
}
template <class _InputIter, class _Predicate>
inline _InputIter find_if(_InputIter __first, __STL_MPW_EXTRA_CONST _InputIter __last,
_Predicate __pred,
input_iterator_tag)
{
__stl_debug_check(__check_range(__first, __last));
while (__first != __last && !__pred(*__first))
++__first;
return __first;
}
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class _RandomAccessIter, class _Tp>
_RandomAccessIter find(_RandomAccessIter __first, _RandomAccessIter __last,
const _Tp& __val,
random_access_iterator_tag);
template <class _RandomAccessIter, class _Predicate>
_RandomAccessIter find_if(_RandomAccessIter __first, _RandomAccessIter __last,
_Predicate __pred,
random_access_iterator_tag);
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// fbp : without partial spec, we essentially have one variant for those.
template <class _InputIter, class _Tp>
inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val)
{
# if defined (__STL_CLASS_PARTIAL_SPECIALIZATION)
return find(__first, __last, __val, __ITERATOR_CATEGORY(__first));
# else
return find(__first, __last, __val, input_iterator_tag());
# endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
}
template <class _InputIter, class _Predicate>
inline _InputIter find_if(_InputIter __first, _InputIter __last,
_Predicate __pred) {
# if defined (__STL_CLASS_PARTIAL_SPECIALIZATION)
return find_if(__first, __last, __pred, __ITERATOR_CATEGORY(__first));
# else
return find_if(__first, __last, __pred, input_iterator_tag());
# endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
}
// adjacent_find.
template <class _ForwardIter>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last);
template <class _ForwardIter, class _BinaryPredicate>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred);
// count and count_if. There are two version of each, one whose return type
// type is void and one (present only if we have partial specialization)
// whose return type is iterator_traits<_InputIter>::difference_type. The
// C++ standard only has the latter version, but the former, which was present
// in the HP STL, is retained for backward compatibility.
template <class _InputIter, class _Tp, class _Size>
void count(_InputIter __first, _InputIter __last, const _Tp& __value,
_Size& __n);
template <class _InputIter, class _Predicate, class _Size>
void count_if(_InputIter __first, _InputIter __last, _Predicate __pred,
_Size& __n);
template <class _InputIter, class _Tp>
__STL_DIFFERENCE_TYPE(_InputIter)
count(_InputIter __first, _InputIter __last, const _Tp& __value);
template <class _InputIter, class _Predicate>
__STL_DIFFERENCE_TYPE(_InputIter)
count_if(_InputIter __first, _InputIter __last, _Predicate __pred);
// search.
template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2);
template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2,
_BinaryPred __predicate);
// search_n. Search for __count consecutive copies of __val.
template <class _ForwardIter, class _Integer, class _Tp>
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
_Integer __count, const _Tp& __val);
template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
_Integer __count, const _Tp& __val,
_BinaryPred __binary_pred);
// swap_ranges
template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2);
// transform
template <class _InputIter, class _OutputIter, class _UnaryOperation>
_OutputIter transform(_InputIter __first, _InputIter __last,
_OutputIter __result, _UnaryOperation __opr);
template <class _InputIter1, class _InputIter2, class _OutputIter,
class _BinaryOperation>
_OutputIter transform(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _OutputIter __result,
_BinaryOperation __binary_op);
// replace, replace_if, replace_copy, replace_copy_if
template <class _ForwardIter, class _Tp>
void replace(_ForwardIter __first, _ForwardIter __last,
const _Tp& __old_value, const _Tp& __new_value);
template <class _ForwardIter, class _Predicate, class _Tp>
void replace_if(_ForwardIter __first, _ForwardIter __last,
_Predicate __pred, const _Tp& __new_value);
template <class _InputIter, class _OutputIter, class _Tp>
_OutputIter replace_copy(_InputIter __first, _InputIter __last,
_OutputIter __result,
const _Tp& __old_value, const _Tp& __new_value);
template <class Iterator, class _OutputIter, class _Predicate, class _Tp>
_OutputIter replace_copy_if(Iterator __first, Iterator __last,
_OutputIter __result,
_Predicate __pred, const _Tp& __new_value);
// generate and generate_n
template <class _ForwardIter, class _Generator>
void generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen);
template <class _OutputIter, class _Size, class _Generator>
_OutputIter generate_n(_OutputIter __first, _Size __n, _Generator __gen);
// remove, remove_if, remove_copy, remove_copy_if
template <class _InputIter, class _OutputIter, class _Tp>
_OutputIter remove_copy(_InputIter __first, _InputIter __last,
_OutputIter __result, const _Tp& __value);
template <class _InputIter, class _OutputIter, class _Predicate>
_OutputIter remove_copy_if(_InputIter __first, _InputIter __last,
_OutputIter __result, _Predicate __pred);
template <class _ForwardIter, class _Tp>
_ForwardIter remove(_ForwardIter __first, _ForwardIter __last,
const _Tp& __value);
template <class _ForwardIter, class _Predicate>
_ForwardIter remove_if(_ForwardIter __first, _ForwardIter __last,
_Predicate __pred);
// unique and unique_copy
template <class _InputIter, class _OutputIter, class _Tp>
_OutputIter __unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result, _Tp*);
template <class _InputIter, class _OutputIter>
inline _OutputIter __unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result,
output_iterator_tag) {
return __unique_copy(__first, __last, __result, __VALUE_TYPE(__first));
}
template <class _InputIter, class _ForwardIter>
_ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result, forward_iterator_tag);
# if defined (__STL_NONTEMPL_BASE_MATCH_BUG)
template <class _InputIter, class _ForwardIter>
inline
_ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result, bidirectional_iterator_tag) {
return __unique_copy(__first, __last, __result, forward_iterator_tag());
}
template <class _InputIter, class _ForwardIter>
inline
_ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result, random_access_iterator_tag) {
return __unique_copy(__first, __last, __result, forward_iterator_tag());
}
# endif /* __STL_NONTEMPL_BASE_MATCH_BUG */
template <class _InputIter, class _OutputIter>
inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result) {
__stl_debug_check(__check_range(__first, __last));
if (__first == __last) return __result;
return __unique_copy(__first, __last, __result,
__ITERATOR_CATEGORY(__result));
}
template <class InputIterator, class OutputIterator, class BinaryPredicate,
class _Tp>
OutputIterator __unique_copy(InputIterator first, InputIterator last,
OutputIterator result,
BinaryPredicate binary_pred, _Tp*);
template <class _InputIter, class _OutputIter, class _BinaryPredicate>
inline _OutputIter __unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result,
_BinaryPredicate __binary_pred,
output_iterator_tag) {
return __unique_copy(__first, __last, __result, __binary_pred,
__VALUE_TYPE(__first));
}
template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
_ForwardIter __unique_copy(_InputIter __first, _InputIter __last,
_ForwardIter __result,
_BinaryPredicate __binary_pred,
forward_iterator_tag);
# if defined (__STL_NONTEMPL_BASE_MATCH_BUG)
template <class InputIterator, class BidirectionalIterator,
class BinaryPredicate>
inline BidirectionalIterator __unique_copy(InputIterator first,
InputIterator last,
BidirectionalIterator result,
BinaryPredicate binary_pred,
bidirectional_iterator_tag) {
return __unique_copy(first, last, result, binary_pred,
forward_iterator_tag());
}
template <class InputIterator, class RandomAccessIterator,
class BinaryPredicate>
inline RandomAccessIterator __unique_copy(InputIterator first,
InputIterator last,
RandomAccessIterator result,
BinaryPredicate binary_pred,
random_access_iterator_tag) {
return __unique_copy(first, last, result, binary_pred,
forward_iterator_tag());
}
# endif /* __STL_NONTEMPL_BASE_MATCH_BUG */
template <class _InputIter, class _OutputIter, class _BinaryPredicate>
inline _OutputIter unique_copy(_InputIter __first, _InputIter __last,
_OutputIter __result,
_BinaryPredicate __binary_pred) {
__stl_debug_check(__check_range(__first, __last));
if (__first == __last) return __result;
return __unique_copy(__first, __last, __result, __binary_pred,
__ITERATOR_CATEGORY(__result));
}
template <class _ForwardIter>
inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
__first = adjacent_find(__first, __last);
return unique_copy(__first, __last, __first);
}
template <class _ForwardIter, class _BinaryPredicate>
inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred) {
__first = adjacent_find(__first, __last, __binary_pred);
return unique_copy(__first, __last, __first, __binary_pred);
}
// reverse and reverse_copy, and their auxiliary functions
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -