/*
*
* 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.
*
*/
#ifndef __STL_ALGO_C
# define __STL_ALGO_C
__STL_BEGIN_NAMESPACE
template <class _BidirectionalIter, class _Distance>
void __merge_without_buffer(_BidirectionalIter __first,
_BidirectionalIter __middle,
_BidirectionalIter __last,
_Distance __len1, _Distance __len2);
template <class _BidirectionalIter, class _Distance, class _Compare>
void __merge_without_buffer(_BidirectionalIter __first,
_BidirectionalIter __middle,
_BidirectionalIter __last,
_Distance __len1, _Distance __len2,
_Compare __comp);
template <class _BidirectionalIter1, class _BidirectionalIter2,
class _BidirectionalIter3>
_BidirectionalIter3 __merge_backward(_BidirectionalIter1 __first1,
_BidirectionalIter1 __last1,
_BidirectionalIter2 __first2,
_BidirectionalIter2 __last2,
_BidirectionalIter3 __result);
template <class _BidirectionalIter1, class _BidirectionalIter2,
class _BidirectionalIter3, class _Compare>
_BidirectionalIter3 __merge_backward(_BidirectionalIter1 __first1,
_BidirectionalIter1 __last1,
_BidirectionalIter2 __first2,
_BidirectionalIter2 __last2,
_BidirectionalIter3 __result,
_Compare __comp);
template <class _Tp>
# if !(defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x420 ))
inline
# endif
const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) {
if (__a < __b)
if (__b < __c)
return __b;
else if (__a < __c)
return __c;
else
return __a;
else if (__a < __c)
return __a;
else if (__b < __c)
return __c;
else
return __b;
}
template <class _Tp, class _Compare>
# if !(defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x420 ))
inline
# endif
const _Tp&
__median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) {
if (__comp(__a, __b))
if (__comp(__b, __c))
return __b;
else if (__comp(__a, __c))
return __c;
else
return __a;
else if (__comp(__a, __c))
return __a;
else if (__comp(__b, __c))
return __c;
else
return __b;
}
template <class _InputIter, class _Function>
_Function for_each(_InputIter __first, _InputIter __last, _Function __f) {
for ( ; __first != __last; ++__first)
__f(*__first);
return __f;
}
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class _RandomAccessIter, class _Tp>
_RandomAccessIter find(_RandomAccessIter __first, _RandomAccessIter __last,
const _Tp& __val,
random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIter>::difference_type __trip_count
= (__last - __first) >> 2;
for ( ; __trip_count > 0 ; --__trip_count) {
if (*__first == __val) return __first;
++__first;
if (*__first == __val) return __first;
++__first;
if (*__first == __val) return __first;
++__first;
if (*__first == __val) return __first;
++__first;
}
switch(__last - __first) {
case 3:
if (*__first == __val) return __first;
++__first;
case 2:
if (*__first == __val) return __first;
++__first;
case 1:
if (*__first == __val) return __first;
++__first;
case 0:
default:
return __last;
}
}
template <class _RandomAccessIter, class _Predicate>
_RandomAccessIter find_if(_RandomAccessIter __first, _RandomAccessIter __last,
_Predicate __pred,
random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIter>::difference_type __trip_count
= (__last - __first) >> 2;
for ( ; __trip_count > 0 ; --__trip_count) {
if (__pred(*__first)) return __first;
++__first;
if (__pred(*__first)) return __first;
++__first;
if (__pred(*__first)) return __first;
++__first;
if (__pred(*__first)) return __first;
++__first;
}
switch(__last - __first) {
case 3:
if (__pred(*__first)) return __first;
++__first;
case 2:
if (__pred(*__first)) return __first;
++__first;
case 1:
if (__pred(*__first)) return __first;
// ++__first;
case 0:
default:
return __last;
}
}
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class _ForwardIter>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) {
__STL_DEBUG_CHECK(__check_range(__first, __last))
if (__first == __last)
return __last;
_ForwardIter __next = __first;
while(++__next != __last) {
if (*__first == *__next)
return __first;
__first = __next;
}
return __last;
}
template <class _ForwardIter, class _BinaryPredicate>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred) {
__STL_DEBUG_CHECK(__check_range(__first, __last))
if (__first == __last)
return __last;
_ForwardIter __next = __first;
while(++__next != __last) {
if (__binary_pred(*__first, *__next))
return __first;
__first = __next;
}
return __last;
}
template <class _InputIter, class _Tp, class _Size>
void count(_InputIter __first, _InputIter __last, const _Tp& __value,
_Size& __n) {
__STL_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (*__first == __value)
++__n;
}
template <class _InputIter, class _Predicate, class _Size>
void count_if(_InputIter __first, _InputIter __last, _Predicate __pred,
_Size& __n) {
__STL_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (__pred(*__first))
++__n;
}
template <class _InputIter, class _Tp>
__STL_DIFFERENCE_TYPE(_InputIter)
count(_InputIter __first, _InputIter __last, const _Tp& __value) {
__STL_DEBUG_CHECK(__check_range(__first, __last))
__STL_DIFFERENCE_TYPE(_InputIter) __n = 0;
for ( ; __first != __last; ++__first)
if (*__first == __value)
++__n;
return __n;
}
template <class _InputIter, class _Predicate>
__STL_DIFFERENCE_TYPE(_InputIter)
count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
__STL_DEBUG_CHECK(__check_range(__first, __last))
__STL_DIFFERENCE_TYPE(_InputIter) __n = 0;
for ( ; __first != __last; ++__first)
if (__pred(*__first))
++__n;
return __n;
}
template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2)
{
__STL_DEBUG_CHECK(__check_range(__first1, __last1))
__STL_DEBUG_CHECK(__check_range(__first2, __last2))
// Test for empty ranges
if (__first1 == __last1 || __first2 == __last2)
return __first1;
// Test for a pattern of length 1.
_ForwardIter2 __tmp(__first2);
++__tmp;
if (__tmp == __last2)
return find(__first1, __last1, *__first2);
// General case.
_ForwardIter2 __p1, __p;
__p1 = __first2; ++__p1;
_For
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
STL源代码 c++标准库函数 源码 (915个子文件)
algorithm 2KB
algorithm 2KB
bitset 2KB
bitset 2KB
_algo.c 83KB
_rope.c 48KB
_istream.c 42KB
_numeric_facets.c 33KB
_deque.c 27KB
_fstream.c 25KB
_tree.c 23KB
_string.c 22KB
c_locale_glibc.c 21KB
_monetary.c 18KB
_limits.c 17KB
_sstream.c 16KB
_hashtable.c 15KB
_bitset.c 15KB
_debug.c 14KB
_time_facets.c 13KB
_alloc.c 12KB
_list.c 9KB
_ostream.c 9KB
_vector.c 9KB
_string_io.c 8KB
_slist.c 8KB
_heap.c 7KB
_streambuf.c 6KB
_numeric.c 5KB
_valarray.c 5KB
_complex.c 4KB
_threads.c 4KB
_ios.c 3KB
_algobase.c 3KB
_slist_base.c 2KB
_locale.c 2KB
_tempbuf.c 1KB
_string_fwd.c 1KB
c_locale.c 847B
cassert 1KB
cassert 1KB
cctype 2KB
cctype 2KB
cerrno 1KB
cerrno 1KB
tlib.cfg 80B
tlib.cfg 74B
BccW32.cfg 30B
cfloat 1KB
cfloat 1KB
ChangeLog 28KB
climits 1KB
climits 1KB
clocale 1KB
clocale 1KB
cmath 6KB
cmath 6KB
complex 2KB
complex 2KB
complex 1KB
configure 99KB
fstream.cpp 28KB
num_get_float.cpp 25KB
num_put_float.cpp 24KB
locale_impl.cpp 21KB
stl_test.cpp 13KB
ctype.cpp 13KB
main.cpp 12KB
iostream.cpp 12KB
locale.cpp 12KB
single.cpp 11KB
time_facets.cpp 11KB
c_locale_stub.cpp 10KB
strstream.cpp 10KB
ios_base.cpp 9KB
locale_catalog.cpp 9KB
nc_alloc.cpp 8KB
complex.cpp 8KB
monetary.cpp 8KB
test_algo.cpp 8KB
complex_exp.cpp 7KB
complex_trig.cpp 7KB
streambuf.cpp 6KB
stdio_streambuf.cpp 6KB
moneypunct_byname_w.cpp 5KB
stl_single.cpp 5KB
test_bit_vector.cpp 5KB
codecvt_byname.cpp 5KB
test_hash_map.cpp 5KB
ctype_w.cpp 4KB
test_hash_set.cpp 4KB
test_vector.cpp 4KB
test_map.cpp 4KB
test_deque.cpp 4KB
num_get.cpp 4KB
codecvt_w.cpp 4KB
test_list.cpp 4KB
message_facets.cpp 4KB
test_rope.cpp 4KB
seek.cpp 4KB
共 915 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
Lenord
- 粉丝: 8
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页