⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stl_algo.h

📁 本系统采用VC开发.可实现点云数据的处理,图像缩放,生成曲面.
💻 H
📖 第 1 页 / 共 5 页
字号:
/* * * 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>__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 _T>inline const _T& __median(const _T& __a, const _T& __b, const _T& __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 _T, class _Compare>inline const _T&__median(const _T& __a, const _T& __b, const _T& __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;}// 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) {  for ( ; __first != __last; ++__first)    __f(*__first);  return __f;}// find and find_if.template <class _InputIter, class _T>inline _InputIter find(_InputIter __first, _InputIter __last, const _T& __val) {  while (__first != __last && *__first != __val)    ++__first;  return __first;}template <class _InputIter, class _Predicate>_InputIter find_if(_InputIter __first, _InputIter __last,                   _Predicate __pred) {  while (__first != __last && !__pred(*__first))    ++__first;  return __first;}// adjacent_find.template <class _ForwardIter>_ForwardIter adjacent_find(_ForwardIter __first, _ForwardIter __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) {  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 _T, class _Size>void count(_InputIter __first, _InputIter __last, const _T& __value,           _Size& __n) {  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) {  for ( ; __first != __last; ++__first)    if (__pred(*__first))      ++__n;}#ifdef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class _InputIter, class _T>typename iterator_traits<_InputIter>::difference_typecount(_InputIter __first, _InputIter __last, const _T& __value) {  typename iterator_traits<_InputIter>::difference_type __n = 0;  for ( ; __first != __last; ++__first)    if (*__first == __value)      ++__n;  return __n;}template <class _InputIter, class _Predicate>typename iterator_traits<_InputIter>::difference_typecount_if(_InputIter __first, _InputIter __last, _Predicate __pred) {  typename iterator_traits<_InputIter>::difference_type __n = 0;  for ( ; __first != __last; ++__first)    if (__pred(*__first))      ++__n;  return __n;}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */// search.template <class _ForwardIter1, class _ForwardIter2>_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,                     _ForwardIter2 __first2, _ForwardIter2 __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;  _ForwardIter1 __current = __first1;  while (__first1 != __last1) {    __first1 = find(__first1, __last1, *__first2);    if (__first1 == __last1)      return __last1;    __p = __p1;    __current = __first1;     if (++__current == __last1)      return __last1;    while (*__current == *__p) {      if (++__p == __last2)        return __first1;      if (++__current == __last1)        return __last1;    }    ++__first1;  }  return __first1;}template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,                     _ForwardIter2 __first2, _ForwardIter2 __last2,                     _BinaryPred  __predicate) {  // 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;  _ForwardIter1 __current = __first1;  while (__first1 != __last1) {    while (__first1 != __last1) {      if (__predicate(*__first1, *__first2))        break;      ++__first1;    }    while (__first1 != __last1 && !__predicate(*__first1, *__first2))      ++__first1;    if (__first1 == __last1)      return __last1;    __p = __p1;    __current = __first1;     if (++__current == __last1) return __last1;    while (__predicate(*__current, *__p)) {      if (++__p == __last2)        return __first1;      if (++__current == __last1)        return __last1;    }    ++__first1;  }  return __first1;}// search_n.  Search for __count consecutive copies of __val.template <class _ForwardIter, class _Integer, class _T>_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,                      _Integer __count, const _T& __val) {  if (__count <= 0)    return __first;  else {    __first = find(__first, __last, __val);    while (__first != __last) {      _Integer __n = __count - 1;      _ForwardIter __i = __first;      ++__i;      while (__i != __last && __n != 0 && *__i == __val) {        ++__i;        --__n;      }      if (__n == 0)        return __first;      else        __first = find(__i, __last, __val);    }    return __last;  }}template <class _ForwardIter, class _Integer, class _T, class _BinaryPred>_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,                      _Integer __count, const _T& __val,                      _BinaryPred __binary_pred) {  if (__count <= 0)    return __first;  else {    while (__first != __last) {      if (__binary_pred(*__first, __val))        break;      ++__first;    }    while (__first != __last) {      _Integer __n = __count - 1;      _ForwardIter __i = __first;      ++__i;      while (__i != __last && __n != 0 && __binary_pred(*__i, __val)) {        ++__i;        --__n;      }      if (__n == 0)        return __first;      else {        while (__i != __last) {          if (__binary_pred(*__i, __val))            break;          ++__i;        }        __first = __i;      }    }    return __last;  }} // swap_rangestemplate <class _ForwardIter1, class _ForwardIter2>_ForwardIter2 swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1,                          _ForwardIter2 __first2) {  for ( ; __first1 != __last1; ++__first1, ++__first2)    iter_swap(__first1, __first2);  return __first2;}// transformtemplate <class _InputIter, class _OutputIter, class _UnaryOperation>_OutputIter transform(_InputIter __first, _InputIter __last,                      _OutputIter __result, _UnaryOperation __opr) {  for ( ; __first != __last; ++__first, ++__result)    *__result = __opr(*__first);  return __result;}template <class _InputIter1, class _InputIter2, class _OutputIter,          class _BinaryOperation>_OutputIter transform(_InputIter1 __first1, _InputIter1 __last1,                      _InputIter2 __first2, _OutputIter __result,                      _BinaryOperation __binary_op) {  for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)    *__result = __binary_op(*__first1, *__first2);  return __result;}// replace, replace_if, replace_copy, replace_copy_iftemplate <class _ForwardIter, class _T>void replace(_ForwardIter __first, _ForwardIter __last,             const _T& __old_value, const _T& __new_value) {  for ( ; __first != __last; ++__first)    if (*__first == __old_value)      *__first = __new_value;}template <class _ForwardIter, class _Predicate, class _T>void replace_if(_ForwardIter __first, _ForwardIter __last,                _Predicate __pred, const _T& __new_value) {  for ( ; __first != __last; ++__first)    if (__pred(*__first))      *__first = __new_value;}template <class _InputIter, class _OutputIter, class _T>_OutputIter replace_copy(_InputIter __first, _InputIter __last,                         _OutputIter __result,                         const _T& __old_value, const _T& __new_value) {  for ( ; __first != __last; ++__first, ++__result)    *__result = *__first == __old_value ? __new_value : *__first;  return __result;}template <class Iterator, class _OutputIter, class _Predicate, class _T>_OutputIter replace_copy_if(Iterator __first, Iterator __last,                            _OutputIter __result,                            _Predicate __pred, const _T& __new_value) {  for ( ; __first != __last; ++__first, ++__result)    *__result = __pred(*__first) ? __new_value : *__first;  return __result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -