/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/* 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
#include <stl_heap.h>
// See concept_checks.h for the concept-checking macros
// __STL_REQUIRES, __STL_CONVERTIBLE, etc.
__STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1209
#endif
// __median (an extension, not present in the C++ standard).
template <class _Tp>
inline const _Tp& __median(const _Tp& __a, const _Tp& __b, const _Tp& __c) {
__STL_REQUIRES(_Tp, _LessThanComparable);
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>
inline const _Tp&
__median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp) {
__STL_BINARY_FUNCTION_CHECK(_Compare, bool, _Tp, _Tp);
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;
}
// 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) {
__STL_REQUIRES(_InputIter, _InputIterator);
for ( ; __first != __last; ++__first)
__f(*__first);
return __f;
}
// find and find_if.
template <class _InputIter, class _Tp>
inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val,
input_iterator_tag)
{
while (__first != __last && !(*__first == __val))
++__first;
return __first;
}
template <class _InputIter, class _Predicate>
inline _InputIter find_if(_InputIter __first, _InputIter __last,
_Predicate __pred,
input_iterator_tag)
{
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)
{
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 _InputIter, class _Tp>
inline _InputIter find(_InputIter __first, _InputIter __last,
const _Tp& __val)
{
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES_BINARY_OP(_OP_EQUAL, bool,
typename iterator_traits<_InputIter>::value_type, _Tp);
return find(__first, __last, __val, __ITERATOR_CATEGORY(__first));
}
template <class _InputIter, class _Predicate>
inline _InputIter find_if(_InputIter __first, _InputIter __last,
_Predicate __pred) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_UNARY_FUNCTION_CHECK(_Predicate, bool,
typename iterator_traits<_InputIter>::value_type);
return find_if(__first, __last, __pred, __ITERATOR_CATEGORY(__first));
}
// adjacent_find.
template <class _ForwardIter>
_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __last) {
__STL_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_REQUIRES(typename iterator_traits<_ForwardIter>::value_type,
_EqualityComparable);
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_REQUIRES(_ForwardIter, _ForwardIterator);
__STL_BINARY_FUNCTION_CHECK(_BinaryPredicate, bool,
typename iterator_traits<_ForwardIter>::value_type,
typename iterator_traits<_ForwardIter>::value_type);
if (__first == __last)
return __last;
_ForwardIter __next = __first;
while(++__next != __last) {
if (__binary_pred(*__first, *__next))
return __first;
__first = __next;
}
return __last;
}
// 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) {
__STL_REQUIRES(_InputIter, _InputIterator);
__STL_REQUIRES(typename iterator_traits<_InputIter>::value_type,
_EqualityComparable);
__STL_REQUIRES(_Tp, _EqualityComparable);
for ( ; __first != __last; ++__first)
if (*__first == __value)
++__n;
}
template <class _InputIter, class _Predicate, class _Size>
void count_if(_InputIter __first, _InputIter __last, _Predicate __pred,
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
SGI STL是Silicon Graphics Inc.(简称SGI)公司开发的标准模板库(Standard Template Library)的一个版本。它是C++标准库的一个重要实现,对STL的发展和推广产生了重大影响。 SGI STL的源码是开源的,其设计和实现体现了诸多优秀的编程思想和技巧。下面是对SGI STL源码的一些关键特点和描述:泛型编程、算法与容器的分离、迭代器、函数对象等。 SGI STL的源码是学习和理解STL实现原理的宝贵资源。它展示了如何使用C++的语言特性和编程技巧来设计和实现高效、灵活、可重用的组件。通过研究SGI STL的源码,可以深入理解STL的内部工作机制,提高编程技能和设计能力。 需要注意的是,虽然SGI STL对STL的发展产生了重大影响,但它并非C++标准库的唯一实现。不同的编译器和标准库实现可能会有所差异,但总体上遵循了STL的设计原则和接口规范。
资源推荐
资源详情
资源评论
收起资源包目录
SGI STL源码.7z (91个子文件)
SGI STL源码
stl_construct.h 4KB
stl_stack.h 4KB
slist.h 830B
stl_vector.h 28KB
stl_iterator.h 29KB
algobase.h 2KB
stl_map.h 10KB
valarray 52KB
list.h 1KB
multimap.h 1KB
stack.h 1KB
set.h 1KB
container_concepts.h 9KB
type_traits.h 13KB
stl_algobase.h 24KB
stl_multimap.h 10KB
ropeimpl.h 47KB
stl_function.h 22KB
iterator.h 3KB
utility 1KB
sequence_concepts.h 7KB
stl_exception.h 2KB
stl_heap.h 10KB
defalloc.h 2KB
stl_numeric.h 8KB
stl_relops.h 2KB
alloc.h 1KB
stl_set.h 9KB
stl_tempbuf.h 5KB
map 1KB
stl_iterator_base.h 12KB
hash_map 1KB
function.h 3KB
stdexcept 2KB
stl_list.h 25KB
stl_hash_set.h 19KB
stl_deque.h 52KB
deque.h 1KB
list 1KB
tempbuf.h 2KB
stl_pair.h 3KB
vector 1KB
map.h 1KB
stack 1KB
stl_rope.h 98KB
functional 762B
limits 20KB
string 74KB
heap.h 1KB
stl_slist.h 31KB
queue 1KB
stl_string_fwd.h 1KB
stl_range_errors.h 2KB
multiset.h 1KB
deque 1KB
bitset 32KB
tree.h 1KB
iterator 1KB
char_traits.h 4KB
stl_config.h 20KB
stl_queue.h 7KB
stl_alloc.h 28KB
rope 924B
concept_checks.h 28KB
algorithm 1KB
stl_hash_map.h 20KB
pthread_alloc 16KB
hash_set.h 1KB
hash_map.h 1KB
memory 3KB
vector.h 1KB
algo.h 3KB
slist 807B
pair.h 1KB
numeric 2KB
stl_ctraits_fns.h 2KB
stl_uninitialized.h 9KB
stl_tree.h 44KB
stl_threads.h 12KB
stl_multiset.h 9KB
pthread_alloc.h 866B
stl_algo.h 111KB
stl_raw_storage_iter.h 3KB
stl_hash_fun.h 3KB
stl_hashtable.h 32KB
bvector.h 1KB
set 1KB
rope.h 909B
hash_set 1KB
hashtable.h 2KB
stl_bvector.h 27KB
共 91 条
- 1
资源评论
排骨炖粉条
- 粉丝: 2276
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功