// Algorithm implementation -*- C++ -*-
// Copyright (C) 2001-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/*
*
* 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.
*/
/** @file bits/stl_algo.h
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{algorithm}
*/
#ifndef _STL_ALGO_H
#define _STL_ALGO_H 1
#include <cstdlib> // for rand
#include <bits/algorithmfwd.h>
#include <bits/stl_heap.h>
#include <bits/stl_tempbuf.h> // for _Temporary_buffer
#if __cplusplus >= 201103L
#include <random> // for std::uniform_int_distribution
#include <functional> // for std::bind
#endif
// See concept_check.h for the __glibcxx_*_requires macros.
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Swaps the median value of *__a, *__b and *__c to *__result
template<typename _Iterator>
void
__move_median_to_first(_Iterator __result, _Iterator __a,
_Iterator __b, _Iterator __c)
{
// concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_Iterator>::value_type>)
if (*__a < *__b)
{
if (*__b < *__c)
std::iter_swap(__result, __b);
else if (*__a < *__c)
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __a);
}
else if (*__a < *__c)
std::iter_swap(__result, __a);
else if (*__b < *__c)
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __b);
}
/// Swaps the median value of *__a, *__b and *__c under __comp to *__result
template<typename _Iterator, typename _Compare>
void
__move_median_to_first(_Iterator __result, _Iterator __a,
_Iterator __b, _Iterator __c,
_Compare __comp)
{
// concept requirements
__glibcxx_function_requires(_BinaryFunctionConcept<_Compare, bool,
typename iterator_traits<_Iterator>::value_type,
typename iterator_traits<_Iterator>::value_type>)
if (__comp(*__a, *__b))
{
if (__comp(*__b, *__c))
std::iter_swap(__result, __b);
else if (__comp(*__a, *__c))
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __a);
}
else if (__comp(*__a, *__c))
std::iter_swap(__result, __a);
else if (__comp(*__b, *__c))
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __b);
}
// for_each
/// This is an overload used by find() for the Input Iterator case.
template<typename _InputIterator, typename _Tp>
inline _InputIterator
__find(_InputIterator __first, _InputIterator __last,
const _Tp& __val, input_iterator_tag)
{
while (__first != __last && !(*__first == __val))
++__first;
return __first;
}
/// This is an overload used by find_if() for the Input Iterator case.
template<typename _InputIterator, typename _Predicate>
inline _InputIterator
__find_if(_InputIterator __first, _InputIterator __last,
_Predicate __pred, input_iterator_tag)
{
while (__first != __last && !bool(__pred(*__first)))
++__first;
return __first;
}
/// This is an overload used by find() for the RAI case.
template<typename _RandomAccessIterator, typename _Tp>
_RandomAccessIterator
__find(_RandomAccessIterator __first, _RandomAccessIterator __last,
const _Tp& __val, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::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;
}
}
/// This is an overload used by find_if() for the RAI case.
template<typename _RandomAccessIterator, typename _Predicate>
_RandomAccessIterator
__find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Predicate __pred, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::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;
}
}
/// This is an overload used by find_if_not() for the Input Iterator case.
template<typename _InputIterator, typename _Predicate>
inline _InputIterator
__find_if_not(_InputIterator __first, _InputIterator __last,
_Predicate __pred, input_iterator_tag)
{
while (__first != __last && bool(__pred(*__first)))
++__first;
return __first;
}
/// This is an overload used by find_if_not() for the RAI case.
template<typename _RandomAccessIterator, typename _Predicate>
_RandomAccessIterator
__find_if_not(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Predicate __pred, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::difference_type
__trip_count = (__last - __first) >> 2;
for (; __trip_count > 0; --__trip_count)
{
if (!bool(__pred(*__first)))
return __first;
++__fir
没有合适的资源?快使用搜索试试~ 我知道了~
linux中gcc4.8.5,下载解压即可直接使用,linux系统GCC编译
需积分: 5 4 下载量 200 浏览量
2023-10-11
10:27:42
上传
评论
收藏 309.64MB GZ 举报
温馨提示
共2000个文件
h:1757个
hpp:243个
linux中gcc4.8.5,下载解压即可直接使用,linux系统GCC编译,已经编译完成
资源推荐
资源详情
资源评论
收起资源包目录
linux中gcc4.8.5,下载解压即可直接使用,linux系统GCC编译 (2000个子文件)
stl_algo.h 213KB
random.h 173KB
basic_string.h 109KB
vstring.h 104KB
locale_facets.h 89KB
regex.h 83KB
random.h 71KB
stl_deque.h 66KB
locale_facets_nonio.h 64KB
hashtable.h 61KB
stl_tree.h 54KB
stl_list.h 53KB
hashtable_policy.h 53KB
stl_vector.h 49KB
unordered_map.h 48KB
ropeimpl.h 47KB
c++config.h 47KB
c++config.h 47KB
forward_list.h 47KB
unordered_set.h 43KB
stl_algobase.h 41KB
shared_ptr_base.h 41KB
hashtable.h 41KB
stl_map.h 37KB
stl_iterator.h 36KB
stl_multimap.h 34KB
hashtable.h 33KB
shared_ptr.h 32KB
javaprims.h 32KB
bitmap_allocator.h 31KB
stl_bvector.h 29KB
stl_set.h 29KB
stl_multiset.h 28KB
ios_base.h 28KB
regex_compiler.h 28KB
boost_concept_check.h 26KB
atomic_base.h 25KB
hashtable_policy.h 25KB
gthr-posix.h 24KB
gthr-default.h 24KB
gthr-posix.h 24KB
gthr-default.h 24KB
safe_iterator.h 23KB
rc_string_base.h 23KB
Class.h 23KB
locale_classes.h 22KB
mt_allocator.h 22KB
valarray_after.h 22KB
stl_function.h 22KB
cxxabi.h 21KB
valarray_array.h 21KB
profiler_trace.h 21KB
algorithmfwd.h 21KB
throw_allocator.h 20KB
stl_heap.h 20KB
stl_uninitialized.h 20KB
pointer.h 19KB
shared_ptr.h 19KB
Component.h 18KB
stl_queue.h 18KB
valarray_before.h 18KB
alloc_traits.h 18KB
unique_ptr.h 17KB
char_traits.h 17KB
decimal.h 17KB
typelist.h 16KB
codecvt.h 16KB
sso_string_base.h 16KB
codecvt_specializations.h 16KB
map.h 16KB
profiler.h 16KB
macros.h 15KB
functions.h 15KB
basic_ios.h 15KB
map.h 14KB
multimap.h 14KB
stl_numeric.h 13KB
set.h 13KB
multiset.h 13KB
formatter.h 13KB
DatabaseMetaData.h 13KB
streambuf_iterator.h 12KB
safe_local_iterator.h 12KB
multimap.h 12KB
RowSet.h 12KB
set.h 12KB
multiset.h 11KB
regex_constants.h 11KB
regex_nfa.h 11KB
auto_ptr.h 10KB
Toolkit.h 10KB
unordered_map.h 10KB
CallableStatement.h 10KB
stl_stack.h 10KB
stl_pair.h 10KB
cpp_type_traits.h 10KB
AWTEventMulticaster.h 9KB
unordered_set.h 9KB
slice_array.h 9KB
ResultSet.h 9KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
chy_wang
- 粉丝: 2300
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功