求调,编译错上天了
  • 板块灌水区
  • 楼主_YangBoXun_
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/7/15 21:07
  • 上次更新2024/7/15 22:14:39
查看原帖
求调,编译错上天了
1334984
_YangBoXun_楼主2024/7/15 21:07
#include<bits/stdc++.h>
#pragma G++ optimize(2)
using namespace std;

const int N  = 101;
int n;
bool cmp(struct a,struct b)
{
	return b > a;
}
struct stu{
	
	int id;
	int c;
	int m;
	int e;
	double avg;
	
}stu[N];

int main(){
std::ios::sync_with_stdio(false);
std::size_t fread(void* buffer, std::size_t size, std::size_t count,std::FILE* stream);
std::size_t fwrite(const void* buffer, std::size_t size, std::size_t count,std::FILE* stream);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> stu[i].id >> stu[i].c >> stu[i].m >> stu[i].e >> stu[i].avg;
		stu[i].avg = (stu[i].c + stu[i].m + stu[i].e) / 3.0;
	}
	sort(stu + 1,stu + n + 1,cmp);
	for(int i = 1;i <= n;i++)
	{
		cout << stu[i].id << fixed << setprecision(1) << stu[i].avg << endl;
	}

	return 0;
}

//我本以为这份代码就要这样完事的事后,他突然报错了。逆天报错请见下

// 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 *__a
template<typename _Iterator>
  void
  __move_median_first(_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(__a, __b);
    else if (*__a < *__c)
      std::iter_swap(__a, __c);
  }
    else if (*__a < *__c)
  return;
    else if (*__b < *__c)
  std::iter_swap(__a, __c);
    else
  std::iter_swap(__a, __b);
  }

/// Swaps the median value of *__a, *__b and *__c under __comp to *__a
template<typename _Iterator, typename _Compare>
  void
  __move_median_first(_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(__a, __b);
    else if (__comp(*__a, *__c))
      std::iter_swap(__a, __c);
  }
    else if (__comp(*__a, *__c))
  return;
    else if (__comp(*__b, *__c))
  std::iter_swap(__a, __c);
    else
  std::iter_swap(__a, __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;
    ++__first;

    if (!bool(__pred(*__first)))
      return __first;
    ++__first;

    if (!bool(__pred(*__first)))
      return __first;
    ++__first;

    if (!bool(__pred(*__first)))
      return __first;
    ++__first;
  }

    switch (__last - __first)
  {
  case 3:
    if (!bool(__pred(*__first)))
      return __first;
    ++__first;
  case 2:
    if (!bool(__pred(*__first)))
      return __first;
    ++__first;
  case 1:
    if (!bool(__pred(*__first)))
      return __first;
    ++__first;
  case 0:
  default:
    return __last;
  }
  }

/// Provided for stable_partition to use.
template<typename _InputIterator, typename _Predicate>
  inline _InputIterator
  __find_if_not(_InputIterator __first, _InputIterator __last,
  	  _Predicate __pred)
  {
    return std::__find_if_not(__first, __last, __pred,
  			std::__iterator_category(__first));
  }

/// Like find_if_not(), but uses and updates a count of the
/// remaining range length instead of comparing against an end
/// iterator.
template<typename _InputIterator, typename _Predicate, typename _Distance>
  _InputIterator
  __find_if_not_n(_InputIterator __first, _Distance& __len, _Predicate __pred)
  {
    for (; __len; --__len, ++__first)
  if (!bool(__pred(*__first)))
    break;
    return __first;
  }

// set_difference
// set_intersection
// set_symmetric_difference
// set_union
// for_each
// find
// find_if
// find_first_of
// adjacent_find
// count
// count_if
// search

/**
 *  This is an uglified
 *  search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&)
 *  overloaded for forward iterators.
*/
template<typename _ForwardIterator, typename _Integer, typename _Tp>
  _ForwardIterator
  __search_n(_ForwardIterator __first, _ForwardIterator __last,
         _Integer __count, const _Tp& __val,
         std::forward_iterator_tag)
  {
    __first = _GLIBCXX_STD_A::find(__first, __last, __val);
    while (__first != __last)
  {
    typename iterator_traits<_ForwardIterator>::difference_type
      __n = __count;
    _ForwardIterator __i = __first;
    ++__i;
    while (__i != __last && __n != 1 && *__i == __val)
      {
        ++__i;
        --__n;
      }
    if (__n == 1)
      return __first;
    if (__i == __last)
      return __last;
    __first = _GLIBCXX_STD_A::find(++__i, __last, __val);
  }
    return __last;
  }

/**
 *  This is an uglified
 *  search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&)
 *  overloaded for random access iterators.
*/
template<typename _RandomAccessIter, typename _Integer, typename _Tp>
  _RandomAccessIter
  __search_n(_RandomAccessIter __first, _RandomAccessIter __last,
         _Integer __count, const _Tp& __val, 
         std::random_access_iterator_tag)
  {
    
    typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
  _DistanceType;

    _DistanceType __tailSize = __last - __first;
    const _DistanceType __pattSize = __count;

    if (__tailSize < __pattSize)
      return __last;

    const _DistanceType __skipOffset = __pattSize - 1;
    _RandomAccessIter __lookAhead = __first + __skipOffset;
    __tailSize -= __pattSize;

    while (1) // the main loop...
  {
    // __lookAhead here is always pointing to the last element of next 
    // possible match.
    while (!(*__lookAhead == __val)) // the skip loop...
      {
        if (__tailSize < __pattSize)
  	return __last;  // Failure
        __lookAhead += __pattSize;
        __tailSize -= __pattSize;
      }
    _DistanceType __remainder = __skipOffset;
    for (_RandomAccessIter __backTrack = __lookAhead - 1; 
         *__backTrack == __val; --__backTrack)
      {
        if (--__remainder == 0)
  	return (__lookAhead - __skipOffset); // Success
      }
    if (__remainder > __tailSize)
      return __last; // Failure
    __lookAhead += __remainder;
    __tailSize -= __remainder;
  }
  }

// search_n

/**
 *  This is an uglified
 *  search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&,
 *	       _BinaryPredicate)
 *  overloaded for forward iterators.
*/
template<typename _ForwardIterator, typename _Integer, typename _Tp,
         typename _BinaryPredicate>
  _ForwardIterator
  __search_n(_ForwardIterator __first, _ForwardIterator __last,
         _Integer __count, const _Tp& __val,
         _BinaryPredicate __binary_pred, std::forward_iterator_tag)
  {
    while (__first != __last && !bool(__binary_pred(*__first, __val)))
      ++__first;

    while (__first != __last)
  {
    typename iterator_traits<_ForwardIterator>::difference_type
      __n = __count;
    _ForwardIterator __i = __first;
    ++__i;
    while (__i != __last && __n != 1 && bool(__binary_pred(*__i, __val)))
      {
        ++__i;
        --__n;
      }
    if (__n == 1)
      return __first;
    if (__i == __last)
      return __last;
    __first = ++__i;
    while (__first != __last
  	 && !bool(__binary_pred(*__first, __val)))
      ++__first;
  }
    return __last;
  }

/**
 *  This is an uglified
 *  search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&,
 *	       _BinaryPredicate)
 *  overloaded for random access iterators.
*/
template<typename _RandomAccessIter, typename _Integer, typename _Tp,
     typename _BinaryPredicate>
  _RandomAccessIter
  __search_n(_RandomAccessIter __first, _RandomAccessIter __last,
         _Integer __count, const _Tp& __val,
         _BinaryPredicate __binary_pred, std::random_access_iterator_tag)
  {
    
    typedef typename std::iterator_traits<_RandomAccessIter>::difference_type
  _DistanceType;

    _DistanceType __tailSize = __last - __first;
    const _DistanceType __pattSize = __count;

    if (__tailSize < __pattSize)
      return __last;

    const _DistanceType __skipOffset = __pattSize - 1;
    _RandomAccessIter __lookAhead = __first + __skipOffset;
    __tailSize -= __pattSize;

    while (1) // the main loop...
  {
    // __lookAhead here is always pointing to the last element of next 
    // possible match.
    while (!bool(__binary_pred(*__lookAhead, __val))) // the skip loop...
      {
        if (__tailSize < __pattSize)
  	return __last;  // Failure
        __lookAhead += __pattSize;
        __tailSize -= __pattSize;
      }
    _DistanceType __remainder = __skipOffset;
    for (_RandomAccessIter __backTrack = __lookAhead - 1; 
         __binary_pred(*__backTrack, __val); --__backTrack)
      {
        if (--__remainder == 0)
  	return (__lookAhead - __skipOffset); // Success
      }
    if (__remainder > __tailSize)
      return __last; // Failure
    __lookAhead += __remainder;
    __tailSize -= __remainder;
  }
  }

// find_end for forward iterators.
template<typename _ForwardIterator1, typename _ForwardIterator2>
  _ForwardIterator1
  __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
         _ForwardIterator2 __first2, _ForwardIterator2 __last2,
         forward_iterator_tag, forward_iterator_tag)
  {
    if (__first2 == __last2)
  return __last1;
    else
  {
    _ForwardIterator1 __result = __last1;
    while (1)
      {
        _ForwardIterator1 __new_result
  	= _GLIBCXX_STD_A::search(__first1, __last1, __first2, __last2);
        if (__new_result == __last1)
  	return __result;
        else
  	{
  	  __result = __new_result;
  	  __first1 = __new_result;
  	  ++__first1;
  	}
      }
  }
  }

template<typename _ForwardIterator1, typename _ForwardIterator2,
     typename _BinaryPredicate>
  _ForwardIterator1
  __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
         _ForwardIterator2 __first2, _ForwardIterator2 __last2,
         forward_iterator_tag, forward_iterator_tag,
         _BinaryPredicate __comp)
  {
    if (__first2 == __last2)
  return __last1;
    else
  {
    _ForwardIterator1 __result = __last1;
    while (1)
      {
        _ForwardIterator1 __new_result
  	= _GLIBCXX_STD_A::search(__first1, __last1, __first2,
  				 __last2, __comp);
        if (__new_result == __last1)
  	return __result;
        else
  	{
  	  __result = __new_result;
  	  __first1 = __new_result;
  	  ++__first1;
  	}
      }
  }
  }

// find_end for bidirectional iterators (much faster).
template<typename _BidirectionalIterator1, typename _BidirectionalIterator2>
  _BidirectionalIterator1
  __find_end(_BidirectionalIterator1 __first1,
         _BidirectionalIterator1 __last1,
         _BidirectionalIterator2 __first2,
         _BidirectionalIterator2 __last2,
         bidirectional_iterator_tag, bidirectional_iterator_tag)
  {
    // concept requirements
    __glibcxx_function_requires(_BidirectionalIteratorConcept<
  			  _BidirectionalIterator1>)
    __glibcxx_function_requires(_BidirectionalIteratorConcept<
  			  _BidirectionalIterator2>)

    typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
    typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;

    _RevIterator1 __rlast1(__first1);
    _RevIterator2 __rlast2(__first2);
    _RevIterator1 __rresult = _GLIBCXX_STD_A::search(_RevIterator1(__last1),
  					       __rlast1,
  					       _RevIterator2(__last2),
  					       __rlast2);

    if (__rresult == __rlast1)
  return __last1;
    else
  {
    _BidirectionalIterator1 __result = __rresult.base();
    std::advance(__result, -std::distance(__first2, __last2));
    return __result;
  }
  }

template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
     typename _BinaryPredicate>
  _BidirectionalIterator1
  __find_end(_BidirectionalIterator1 __first1,
         _BidirectionalIterator1 __last1,
         _BidirectionalIterator2 __first2,
         _BidirectionalIterator2 __last2,
         bidirectional_iterator_tag, bidirectional_iterator_tag,
         _BinaryPredicate __comp)
  {
    // concept requirements
    __glibcxx_function_requires(_BidirectionalIteratorConcept<
  			  _BidirectionalIterator1>)
    __glibcxx_function_requires(_BidirectionalIteratorConcept<
  			  _BidirectionalIterator2>)

    typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
    typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;

    _RevIterator1 __rlast1(__first1);
    _RevIterator2 __rlast2(__first2);
    _RevIterator1 __rresult = std::search(_RevIterator1(__last1), __rlast1,
  				    _RevIterator2(__last2), __rlast2,
  				    __comp);

    if (__rresult == __rlast1)
  return __last1;
    else
  {
    _BidirectionalIterator1 __result = __rresult.base();
    std::advance(__result, -std::distance(__first2, __last2));
    return __result;
  }
  }

/**
 *  @brief  Find last matching subsequence in a sequence.
 *  @ingroup non_mutating_algorithms
 *  @param  __first1  Start of range to search.
 *  @param  __last1   End of range to search.
 *  @param  __first2  Start of sequence to match.
 *  @param  __last2   End of sequence to match.
 *  @return   The last iterator @c i in the range
 *  @p [__first1,__last1-(__last2-__first2)) such that @c *(i+N) ==
 *  @p *(__first2+N) for each @c N in the range @p
 *  [0,__last2-__first2), or @p __last1 if no such iterator exists.
 *
 *  Searches the range @p [__first1,__last1) for a sub-sequence that
 *  compares equal value-by-value with the sequence given by @p
 *  [__first2,__last2) and returns an iterator to the __first
 *  element of the sub-sequence, or @p __last1 if the sub-sequence
 *  is not found.  The sub-sequence will be the last such
 *  subsequence contained in [__first,__last1).
 *
 *  Because the sub-sequence must lie completely within the range @p
 *  [__first1,__last1) it must start at a position less than @p
 *  __last1-(__last2-__first2) where @p __last2-__first2 is the
 *  length of the sub-sequence.  This means that the returned
 *  iterator @c i will be in the range @p
 *  [__first1,__last1-(__last2-__first2))
*/
template<typename _ForwardIterator1, typename _ForwardIterator2>
  inline _ForwardIterator1
  find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
       _ForwardIterator2 __first2, _ForwardIterator2 __last2)
  {
    // concept requirements
    __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
    __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
    __glibcxx_function_requires(_EqualOpConcept<
      typename iterator_traits<_ForwardIterator1>::value_type,
      typename iterator_traits<_ForwardIterator2>::value_type>)
    __glibcxx_requires_valid_range(__first1, __last1);
    __glibcxx_requires_valid_range(__first2, __last2);

    return std::__find_end(__first1, __last1, __first2, __last2,
  		     std::__iterator_category(__first1),
  		     std::__iterator_category(__first2));
  }

/**
 *  @brief  Find last matching subsequence in a sequence using a predicate.
 *  @ingroup non_mutating_algorithms
 *  @param  __first1  Start of range to search.
 *  @param  __last1   End of range to search.
 *  @param  __first2  Start of sequence to match.
 *  @param  __last2   End of sequence to match.
 *  @param  __comp    The predicate to use.
 *  @return The last iterator @c i in the range @p
 *  [__first1,__last1-(__last2-__first2)) such that @c
 *  predicate(*(i+N), @p (__first2+N)) is true for each @c N in the
 *  range @p [0,__last2-__first2), or @p __last1 if no such iterator
 *  exists.
 *
 *  Searches the range @p [__first1,__last1) for a sub-sequence that
 *  compares equal value-by-value with the sequence given by @p
 *  [__first2,__last2) using comp as a predicate and returns an
 *  iterator to the first element of the sub-sequence, or @p __last1
 *  if the sub-sequence is not found.  The sub-sequence will be the
 *  last such subsequence contained in [__first,__last1).
 *
 *  Because the sub-sequence must lie completely within the range @p
 *  [__first1,__last1) it must start at a position less than @p
 *  __last1-(__last2-__first2) where @p __last2-__first2 is the
 *  length of the sub-sequence.  This means that the returned
 *  iterator @c i will be in the range @p
 *  [__first1,__last1-(__last2-__first2))
*/
template<typename _ForwardIterator1, typename _ForwardIterator2,
     typename _BinaryPredicate>
  inline _ForwardIterator1
  find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
       _ForwardIterator2 __first2, _ForwardIterator2 __last2,
       _BinaryPredicate __comp)
  {
    // concept requirements
    __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
    __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
    __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
      typename iterator_traits<_ForwardIterator1>::value_type,
      typename iterator_traits<_ForwardIterator2>::value_type>)
    __glibcxx_requires_valid_range(__first1, __last1);
    __glibcxx_requires_valid_range(__first2, __last2);

    return std::__find_end(__first1, __last1, __first2, __last2,
  		     std::__iterator_category(__first1),
  		     std::__iterator_category(__first2),
  		     __comp);
  }

#if __cplusplus >= 201103L
/**
 *  @brief  Checks that a predicate is true for all the elements
 *          of a sequence.
 *  @ingroup non_mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __pred    A predicate.
 *  @return  True if the check is true, false otherwise.
 *
 *  Returns true if @p __pred is true for each element in the range
 *  @p [__first,__last), and false otherwise.
*/
template<typename _InputIterator, typename _Predicate>
  inline bool
  all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
  { return __last == std::find_if_not(__first, __last, __pred); }

/**
 *  @brief  Checks that a predicate is false for all the elements
 *          of a sequence.
 *  @ingroup non_mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __pred    A predicate.
 *  @return  True if the check is true, false otherwise.
 *
 *  Returns true if @p __pred is false for each element in the range
 *  @p [__first,__last), and false otherwise.
*/
template<typename _InputIterator, typename _Predicate>
  inline bool
  none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
  { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); }

/**
 *  @brief  Checks that a predicate is false for at least an element
 *          of a sequence.
 *  @ingroup non_mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __pred    A predicate.
 *  @return  True if the check is true, false otherwise.
 *
 *  Returns true if an element exists in the range @p
 *  [__first,__last) such that @p __pred is true, and false
 *  otherwise.
*/
template<typename _InputIterator, typename _Predicate>
  inline bool
  any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
  { return !std::none_of(__first, __last, __pred); }

/**
 *  @brief  Find the first element in a sequence for which a
 *          predicate is false.
 *  @ingroup non_mutating_algorithms
 *  @param  __first  An input iterator.
 *  @param  __last   An input iterator.
 *  @param  __pred   A predicate.
 *  @return   The first iterator @c i in the range @p [__first,__last)
 *  such that @p __pred(*i) is false, or @p __last if no such iterator exists.
*/
template<typename _InputIterator, typename _Predicate>
  inline _InputIterator
  find_if_not(_InputIterator __first, _InputIterator __last,
  	_Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
        typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);
    return std::__find_if_not(__first, __last, __pred);
  }

/**
 *  @brief  Checks whether the sequence is partitioned.
 *  @ingroup mutating_algorithms
 *  @param  __first  An input iterator.
 *  @param  __last   An input iterator.
 *  @param  __pred   A predicate.
 *  @return  True if the range @p [__first,__last) is partioned by @p __pred,
 *  i.e. if all elements that satisfy @p __pred appear before those that
 *  do not.
*/
template<typename _InputIterator, typename _Predicate>
  inline bool
  is_partitioned(_InputIterator __first, _InputIterator __last,
  	   _Predicate __pred)
  {
    __first = std::find_if_not(__first, __last, __pred);
    return std::none_of(__first, __last, __pred);
  }

/**
 *  @brief  Find the partition point of a partitioned range.
 *  @ingroup mutating_algorithms
 *  @param  __first   An iterator.
 *  @param  __last    Another iterator.
 *  @param  __pred    A predicate.
 *  @return  An iterator @p mid such that @p all_of(__first, mid, __pred)
 *           and @p none_of(mid, __last, __pred) are both true.
*/
template<typename _ForwardIterator, typename _Predicate>
  _ForwardIterator
  partition_point(_ForwardIterator __first, _ForwardIterator __last,
  	    _Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
        typename iterator_traits<_ForwardIterator>::value_type>)

    // A specific debug-mode test will be necessary...
    __glibcxx_requires_valid_range(__first, __last);

    typedef typename iterator_traits<_ForwardIterator>::difference_type
  _DistanceType;

    _DistanceType __len = std::distance(__first, __last);
    _DistanceType __half;
    _ForwardIterator __middle;

    while (__len > 0)
  {
    __half = __len >> 1;
    __middle = __first;
    std::advance(__middle, __half);
    if (__pred(*__middle))
      {
        __first = __middle;
        ++__first;
        __len = __len - __half - 1;
      }
    else
      __len = __half;
  }
    return __first;
  }
#endif


/**
 *  @brief Copy a sequence, removing elements of a given value.
 *  @ingroup mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __result  An output iterator.
 *  @param  __value   The value to be removed.
 *  @return   An iterator designating the end of the resulting sequence.
 *
 *  Copies each element in the range @p [__first,__last) not equal
 *  to @p __value to the range beginning at @p __result.
 *  remove_copy() is stable, so the relative order of elements that
 *  are copied is unchanged.
*/
template<typename _InputIterator, typename _OutputIterator, typename _Tp>
  _OutputIterator
  remove_copy(_InputIterator __first, _InputIterator __last,
  	_OutputIterator __result, const _Tp& __value)
  {
    // concept requirements
    __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_function_requires(_EqualOpConcept<
      typename iterator_traits<_InputIterator>::value_type, _Tp>)
    __glibcxx_requires_valid_range(__first, __last);

    for (; __first != __last; ++__first)
  if (!(*__first == __value))
    {
      *__result = *__first;
      ++__result;
    }
    return __result;
  }

/**
 *  @brief Copy a sequence, removing elements for which a predicate is true.
 *  @ingroup mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __result  An output iterator.
 *  @param  __pred    A predicate.
 *  @return   An iterator designating the end of the resulting sequence.
 *
 *  Copies each element in the range @p [__first,__last) for which
 *  @p __pred returns false to the range beginning at @p __result.
 *
 *  remove_copy_if() is stable, so the relative order of elements that are
 *  copied is unchanged.
*/
template<typename _InputIterator, typename _OutputIterator,
     typename _Predicate>
  _OutputIterator
  remove_copy_if(_InputIterator __first, _InputIterator __last,
  	   _OutputIterator __result, _Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    for (; __first != __last; ++__first)
  if (!bool(__pred(*__first)))
    {
      *__result = *__first;
      ++__result;
    }
    return __result;
  }

#if __cplusplus >= 201103L
/**
 *  @brief Copy the elements of a sequence for which a predicate is true.
 *  @ingroup mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __result  An output iterator.
 *  @param  __pred    A predicate.
 *  @return   An iterator designating the end of the resulting sequence.
 *
 *  Copies each element in the range @p [__first,__last) for which
 *  @p __pred returns true to the range beginning at @p __result.
 *
 *  copy_if() is stable, so the relative order of elements that are
 *  copied is unchanged.
*/
template<typename _InputIterator, typename _OutputIterator,
     typename _Predicate>
  _OutputIterator
  copy_if(_InputIterator __first, _InputIterator __last,
      _OutputIterator __result, _Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    for (; __first != __last; ++__first)
  if (__pred(*__first))
    {
      *__result = *__first;
      ++__result;
    }
    return __result;
  }


template<typename _InputIterator, typename _Size, typename _OutputIterator>
  _OutputIterator
  __copy_n(_InputIterator __first, _Size __n,
       _OutputIterator __result, input_iterator_tag)
  {
    if (__n > 0)
  {
    while (true)
      {
        *__result = *__first;
        ++__result;
        if (--__n > 0)
  	++__first;
        else
  	break;
      }
  }
    return __result;
  }

template<typename _RandomAccessIterator, typename _Size,
     typename _OutputIterator>
  inline _OutputIterator
  __copy_n(_RandomAccessIterator __first, _Size __n,
       _OutputIterator __result, random_access_iterator_tag)
  { return std::copy(__first, __first + __n, __result); }

/**
 *  @brief Copies the range [first,first+n) into [result,result+n).
 *  @ingroup mutating_algorithms
 *  @param  __first  An input iterator.
 *  @param  __n      The number of elements to copy.
 *  @param  __result An output iterator.
 *  @return  result+n.
 *
 *  This inline function will boil down to a call to @c memmove whenever
 *  possible.  Failing that, if random access iterators are passed, then the
 *  loop count will be known (and therefore a candidate for compiler
 *  optimizations such as unrolling).
*/
template<typename _InputIterator, typename _Size, typename _OutputIterator>
  inline _OutputIterator
  copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
  {
    // concept requirements
    __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
      typename iterator_traits<_InputIterator>::value_type>)

    return std::__copy_n(__first, __n, __result,
  		   std::__iterator_category(__first));
  }

/**
 *  @brief Copy the elements of a sequence to separate output sequences
 *         depending on the truth value of a predicate.
 *  @ingroup mutating_algorithms
 *  @param  __first   An input iterator.
 *  @param  __last    An input iterator.
 *  @param  __out_true   An output iterator.
 *  @param  __out_false  An output iterator.
 *  @param  __pred    A predicate.
 *  @return   A pair designating the ends of the resulting sequences.
 *
 *  Copies each element in the range @p [__first,__last) for which
 *  @p __pred returns true to the range beginning at @p out_true
 *  and each element for which @p __pred returns false to @p __out_false.
*/
template<typename _InputIterator, typename _OutputIterator1,
     typename _OutputIterator2, typename _Predicate>
  pair<_OutputIterator1, _OutputIterator2>
  partition_copy(_InputIterator __first, _InputIterator __last,
  	   _OutputIterator1 __out_true, _OutputIterator2 __out_false,
  	   _Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator1,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator2,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
      typename iterator_traits<_InputIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);
    
    for (; __first != __last; ++__first)
  if (__pred(*__first))
    {
      *__out_true = *__first;
      ++__out_true;
    }
  else
    {
      *__out_false = *__first;
      ++__out_false;
    }

    return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
  }
#endif

/**
 *  @brief Remove elements from a sequence.
 *  @ingroup mutating_algorithms
 *  @param  __first  An input iterator.
 *  @param  __last   An input iterator.
 *  @param  __value  The value to be removed.
 *  @return   An iterator designating the end of the resulting sequence.
 *
 *  All elements equal to @p __value are removed from the range
 *  @p [__first,__last).
 *
 *  remove() is stable, so the relative order of elements that are
 *  not removed is unchanged.
 *
 *  Elements between the end of the resulting sequence and @p __last
 *  are still present, but their value is unspecified.
*/
template<typename _ForwardIterator, typename _Tp>
  _ForwardIterator
  remove(_ForwardIterator __first, _ForwardIterator __last,
     const _Tp& __value)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  			  _ForwardIterator>)
    __glibcxx_function_requires(_EqualOpConcept<
      typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
    __glibcxx_requires_valid_range(__first, __last);

    __first = _GLIBCXX_STD_A::find(__first, __last, __value);
    if(__first == __last)
      return __first;
    _ForwardIterator __result = __first;
    ++__first;
    for(; __first != __last; ++__first)
      if(!(*__first == __value))
        {
          *__result = _GLIBCXX_MOVE(*__first);
          ++__result;
        }
    return __result;
  }

/**
 *  @brief Remove elements from a sequence using a predicate.
 *  @ingroup mutating_algorithms
 *  @param  __first  A forward iterator.
 *  @param  __last   A forward iterator.
 *  @param  __pred   A predicate.
 *  @return   An iterator designating the end of the resulting sequence.
 *
 *  All elements for which @p __pred returns true are removed from the range
 *  @p [__first,__last).
 *
 *  remove_if() is stable, so the relative order of elements that are
 *  not removed is unchanged.
 *
 *  Elements between the end of the resulting sequence and @p __last
 *  are still present, but their value is unspecified.
*/
template<typename _ForwardIterator, typename _Predicate>
  _ForwardIterator
  remove_if(_ForwardIterator __first, _ForwardIterator __last,
        _Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  			  _ForwardIterator>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
      typename iterator_traits<_ForwardIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    __first = _GLIBCXX_STD_A::find_if(__first, __last, __pred);
    if(__first == __last)
      return __first;
    _ForwardIterator __result = __first;
    ++__first;
    for(; __first != __last; ++__first)
      if(!bool(__pred(*__first)))
        {
          *__result = _GLIBCXX_MOVE(*__first);
          ++__result;
        }
    return __result;
  }

/**
 *  @brief Remove consecutive duplicate values from a sequence.
 *  @ingroup mutating_algorithms
 *  @param  __first  A forward iterator.
 *  @param  __last   A forward iterator.
 *  @return  An iterator designating the end of the resulting sequence.
 *
 *  Removes all but the first element from each group of consecutive
 *  values that compare equal.
 *  unique() is stable, so the relative order of elements that are
 *  not removed is unchanged.
 *  Elements between the end of the resulting sequence and @p __last
 *  are still present, but their value is unspecified.
*/
template<typename _ForwardIterator>
  _ForwardIterator
  unique(_ForwardIterator __first, _ForwardIterator __last)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  			  _ForwardIterator>)
    __glibcxx_function_requires(_EqualityComparableConcept<
  	     typename iterator_traits<_ForwardIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    // Skip the beginning, if already unique.
    __first = _GLIBCXX_STD_A::adjacent_find(__first, __last);
    if (__first == __last)
  return __last;

    // Do the real copy work.
    _ForwardIterator __dest = __first;
    ++__first;
    while (++__first != __last)
  if (!(*__dest == *__first))
    *++__dest = _GLIBCXX_MOVE(*__first);
    return ++__dest;
  }

/**
 *  @brief Remove consecutive values from a sequence using a predicate.
 *  @ingroup mutating_algorithms
 *  @param  __first        A forward iterator.
 *  @param  __last         A forward iterator.
 *  @param  __binary_pred  A binary predicate.
 *  @return  An iterator designating the end of the resulting sequence.
 *
 *  Removes all but the first element from each group of consecutive
 *  values for which @p __binary_pred returns true.
 *  unique() is stable, so the relative order of elements that are
 *  not removed is unchanged.
 *  Elements between the end of the resulting sequence and @p __last
 *  are still present, but their value is unspecified.
*/
template<typename _ForwardIterator, typename _BinaryPredicate>
  _ForwardIterator
  unique(_ForwardIterator __first, _ForwardIterator __last,
         _BinaryPredicate __binary_pred)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  			  _ForwardIterator>)
    __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
  	typename iterator_traits<_ForwardIterator>::value_type,
  	typename iterator_traits<_ForwardIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    // Skip the beginning, if already unique.
    __first = _GLIBCXX_STD_A::adjacent_find(__first, __last, __binary_pred);
    if (__first == __last)
  return __last;

    // Do the real copy work.
    _ForwardIterator __dest = __first;
    ++__first;
    while (++__first != __last)
  if (!bool(__binary_pred(*__dest, *__first)))
    *++__dest = _GLIBCXX_MOVE(*__first);
    return ++__dest;
  }

/**
 *  This is an uglified unique_copy(_InputIterator, _InputIterator,
 *                                  _OutputIterator)
 *  overloaded for forward iterators and output iterator as result.
*/
template<typename _ForwardIterator, typename _OutputIterator>
  _OutputIterator
  __unique_copy(_ForwardIterator __first, _ForwardIterator __last,
  	  _OutputIterator __result,
  	  forward_iterator_tag, output_iterator_tag)
  {
    // concept requirements -- taken care of in dispatching function
    _ForwardIterator __next = __first;
    *__result = *__first;
    while (++__next != __last)
  if (!(*__first == *__next))
    {
      __first = __next;
      *++__result = *__first;
    }
    return ++__result;
  }

/**
 *  This is an uglified unique_copy(_InputIterator, _InputIterator,
 *                                  _OutputIterator)
 *  overloaded for input iterators and output iterator as result.
*/
template<typename _InputIterator, typename _OutputIterator>
  _OutputIterator
  __unique_copy(_InputIterator __first, _InputIterator __last,
  	  _OutputIterator __result,
  	  input_iterator_tag, output_iterator_tag)
  {
    // concept requirements -- taken care of in dispatching function
    typename iterator_traits<_InputIterator>::value_type __value = *__first;
    *__result = __value;
    while (++__first != __last)
  if (!(__value == *__first))
    {
      __value = *__first;
      *++__result = __value;
    }
    return ++__result;
  }

/**
 *  This is an uglified unique_copy(_InputIterator, _InputIterator,
 *                                  _OutputIterator)
 *  overloaded for input iterators and forward iterator as result.
*/
template<typename _InputIterator, typename _ForwardIterator>
  _ForwardIterator
  __unique_copy(_InputIterator __first, _InputIterator __last,
  	  _ForwardIterator __result,
  	  input_iterator_tag, forward_iterator_tag)
  {
    // concept requirements -- taken care of in dispatching function
    *__result = *__first;
    while (++__first != __last)
  if (!(*__result == *__first))
    *++__result = *__first;
    return ++__result;
  }

/**
 *  This is an uglified
 *  unique_copy(_InputIterator, _InputIterator, _OutputIterator,
 *              _BinaryPredicate)
 *  overloaded for forward iterators and output iterator as result.
*/
template<typename _ForwardIterator, typename _OutputIterator,
     typename _BinaryPredicate>
  _OutputIterator
  __unique_copy(_ForwardIterator __first, _ForwardIterator __last,
  	  _OutputIterator __result, _BinaryPredicate __binary_pred,
  	  forward_iterator_tag, output_iterator_tag)
  {
    // concept requirements -- iterators already checked
    __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
    typename iterator_traits<_ForwardIterator>::value_type,
    typename iterator_traits<_ForwardIterator>::value_type>)

    _ForwardIterator __next = __first;
    *__result = *__first;
    while (++__next != __last)
  if (!bool(__binary_pred(*__first, *__next)))
    {
      __first = __next;
      *++__result = *__first;
    }
    return ++__result;
  }

/**
 *  This is an uglified
 *  unique_copy(_InputIterator, _InputIterator, _OutputIterator,
 *              _BinaryPredicate)
 *  overloaded for input iterators and output iterator as result.
*/
template<typename _InputIterator, typename _OutputIterator,
     typename _BinaryPredicate>
  _OutputIterator
  __unique_copy(_InputIterator __first, _InputIterator __last,
  	  _OutputIterator __result, _BinaryPredicate __binary_pred,
  	  input_iterator_tag, output_iterator_tag)
  {
    // concept requirements -- iterators already checked
    __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
    typename iterator_traits<_InputIterator>::value_type,
    typename iterator_traits<_InputIterator>::value_type>)

    typename iterator_traits<_InputIterator>::value_type __value = *__first;
    *__result = __value;
    while (++__first != __last)
  if (!bool(__binary_pred(__value, *__first)))
    {
      __value = *__first;
      *++__result = __value;
    }
    return ++__result;
  }

/**
 *  This is an uglified
 *  unique_copy(_InputIterator, _InputIterator, _OutputIterator,
 *              _BinaryPredicate)
 *  overloaded for input iterators and forward iterator as result.
*/
template<typename _InputIterator, typename _ForwardIterator,
     typename _BinaryPredicate>
  _ForwardIterator
  __unique_copy(_InputIterator __first, _InputIterator __last,
  	  _ForwardIterator __result, _BinaryPredicate __binary_pred,
  	  input_iterator_tag, forward_iterator_tag)
  {
    // concept requirements -- iterators already checked
    __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
    typename iterator_traits<_ForwardIterator>::value_type,
    typename iterator_traits<_InputIterator>::value_type>)

    *__result = *__first;
    while (++__first != __last)
  if (!bool(__binary_pred(*__result, *__first)))
    *++__result = *__first;
    return ++__result;
  }

/**
 *  This is an uglified reverse(_BidirectionalIterator,
 *                              _BidirectionalIterator)
 *  overloaded for bidirectional iterators.
*/
template<typename _BidirectionalIterator>
  void
  __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
        bidirectional_iterator_tag)
  {
    while (true)
  if (__first == __last || __first == --__last)
    return;
  else
    {
      std::iter_swap(__first, __last);
      ++__first;
    }
  }

/**
 *  This is an uglified reverse(_BidirectionalIterator,
 *                              _BidirectionalIterator)
 *  overloaded for random access iterators.
*/
template<typename _RandomAccessIterator>
  void
  __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
        random_access_iterator_tag)
  {
    if (__first == __last)
  return;
    --__last;
    while (__first < __last)
  {
    std::iter_swap(__first, __last);
    ++__first;
    --__last;
  }
  }

/**
 *  @brief Reverse a sequence.
 *  @ingroup mutating_algorithms
 *  @param  __first  A bidirectional iterator.
 *  @param  __last   A bidirectional iterator.
 *  @return   reverse() returns no value.
 *
 *  Reverses the order of the elements in the range @p [__first,__last),
 *  so that the first element becomes the last etc.
 *  For every @c i such that @p 0<=i<=(__last-__first)/2), @p reverse()
 *  swaps @p *(__first+i) and @p *(__last-(i+1))
*/
template<typename _BidirectionalIterator>
  inline void
  reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
  			  _BidirectionalIterator>)
    __glibcxx_requires_valid_range(__first, __last);
    std::__reverse(__first, __last, std::__iterator_category(__first));
  }

/**
 *  @brief Copy a sequence, reversing its elements.
 *  @ingroup mutating_algorithms
 *  @param  __first   A bidirectional iterator.
 *  @param  __last    A bidirectional iterator.
 *  @param  __result  An output iterator.
 *  @return  An iterator designating the end of the resulting sequence.
 *
 *  Copies the elements in the range @p [__first,__last) to the
 *  range @p [__result,__result+(__last-__first)) such that the
 *  order of the elements is reversed.  For every @c i such that @p
 *  0<=i<=(__last-__first), @p reverse_copy() performs the
 *  assignment @p *(__result+(__last-__first)-1-i) = *(__first+i).
 *  The ranges @p [__first,__last) and @p
 *  [__result,__result+(__last-__first)) must not overlap.
*/
template<typename _BidirectionalIterator, typename _OutputIterator>
  _OutputIterator
  reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
  	 _OutputIterator __result)
  {
    // concept requirements
    __glibcxx_function_requires(_BidirectionalIteratorConcept<
  			  _BidirectionalIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  	typename iterator_traits<_BidirectionalIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    while (__first != __last)
  {
    --__last;
    *__result = *__last;
    ++__result;
  }
    return __result;
  }

/**
 *  This is a helper function for the rotate algorithm specialized on RAIs.
 *  It returns the greatest common divisor of two integer values.
*/
template<typename _EuclideanRingElement>
  _EuclideanRingElement
  __gcd(_EuclideanRingElement __m, _EuclideanRingElement __n)
  {
    while (__n != 0)
  {
    _EuclideanRingElement __t = __m % __n;
    __m = __n;
    __n = __t;
  }
    return __m;
  }

/// This is a helper function for the rotate algorithm.
template<typename _ForwardIterator>
  void
  __rotate(_ForwardIterator __first,
       _ForwardIterator __middle,
       _ForwardIterator __last,
       forward_iterator_tag)
  {
    if (__first == __middle || __last  == __middle)
  return;

    _ForwardIterator __first2 = __middle;
    do
  {
    std::iter_swap(__first, __first2);
    ++__first;
    ++__first2;
    if (__first == __middle)
      __middle = __first2;
  }
    while (__first2 != __last);

    __first2 = __middle;

    while (__first2 != __last)
  {
    std::iter_swap(__first, __first2);
    ++__first;
    ++__first2;
    if (__first == __middle)
      __middle = __first2;
    else if (__first2 == __last)
      __first2 = __middle;
  }
  }

 /// This is a helper function for the rotate algorithm.
template<typename _BidirectionalIterator>
  void
  __rotate(_BidirectionalIterator __first,
       _BidirectionalIterator __middle,
       _BidirectionalIterator __last,
        bidirectional_iterator_tag)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
  			  _BidirectionalIterator>)

    if (__first == __middle || __last  == __middle)
  return;

    std::__reverse(__first,  __middle, bidirectional_iterator_tag());
    std::__reverse(__middle, __last,   bidirectional_iterator_tag());

    while (__first != __middle && __middle != __last)
  {
    std::iter_swap(__first, --__last);
    ++__first;
  }

    if (__first == __middle)
  std::__reverse(__middle, __last,   bidirectional_iterator_tag());
    else
  std::__reverse(__first,  __middle, bidirectional_iterator_tag());
  }

/// This is a helper function for the rotate algorithm.
template<typename _RandomAccessIterator>
  void
  __rotate(_RandomAccessIterator __first,
       _RandomAccessIterator __middle,
       _RandomAccessIterator __last,
       random_access_iterator_tag)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
  			  _RandomAccessIterator>)

    if (__first == __middle || __last  == __middle)
  return;

    typedef typename iterator_traits<_RandomAccessIterator>::difference_type
  _Distance;
    typedef typename iterator_traits<_RandomAccessIterator>::value_type
  _ValueType;

    _Distance __n = __last   - __first;
    _Distance __k = __middle - __first;

    if (__k == __n - __k)
  {
    std::swap_ranges(__first, __middle, __middle);
    return;
  }

    _RandomAccessIterator __p = __first;

    for (;;)
  {
    if (__k < __n - __k)
      {
        if (__is_pod(_ValueType) && __k == 1)
  	{
  	  _ValueType __t = _GLIBCXX_MOVE(*__p);
  	  _GLIBCXX_MOVE3(__p + 1, __p + __n, __p);
  	  *(__p + __n - 1) = _GLIBCXX_MOVE(__t);
  	  return;
  	}
        _RandomAccessIterator __q = __p + __k;
        for (_Distance __i = 0; __i < __n - __k; ++ __i)
  	{
  	  std::iter_swap(__p, __q);
  	  ++__p;
  	  ++__q;
  	}
        __n %= __k;
        if (__n == 0)
  	return;
        std::swap(__n, __k);
        __k = __n - __k;
      }
    else
      {
        __k = __n - __k;
        if (__is_pod(_ValueType) && __k == 1)
  	{
  	  _ValueType __t = _GLIBCXX_MOVE(*(__p + __n - 1));
  	  _GLIBCXX_MOVE_BACKWARD3(__p, __p + __n - 1, __p + __n);
  	  *__p = _GLIBCXX_MOVE(__t);
  	  return;
  	}
        _RandomAccessIterator __q = __p + __n;
        __p = __q - __k;
        for (_Distance __i = 0; __i < __n - __k; ++ __i)
  	{
  	  --__p;
  	  --__q;
  	  std::iter_swap(__p, __q);
  	}
        __n %= __k;
        if (__n == 0)
  	return;
        std::swap(__n, __k);
      }
  }
  }

/**
 *  @brief Rotate the elements of a sequence.
 *  @ingroup mutating_algorithms
 *  @param  __first   A forward iterator.
 *  @param  __middle  A forward iterator.
 *  @param  __last    A forward iterator.
 *  @return  Nothing.
 *
 *  Rotates the elements of the range @p [__first,__last) by 
 *  @p (__middle - __first) positions so that the element at @p __middle
 *  is moved to @p __first, the element at @p __middle+1 is moved to
 *  @p __first+1 and so on for each element in the range
 *  @p [__first,__last).
 *
 *  This effectively swaps the ranges @p [__first,__middle) and
 *  @p [__middle,__last).
 *
 *  Performs
 *   @p *(__first+(n+(__last-__middle))%(__last-__first))=*(__first+n)
 *  for each @p n in the range @p [0,__last-__first).
*/
template<typename _ForwardIterator>
  inline void
  rotate(_ForwardIterator __first, _ForwardIterator __middle,
     _ForwardIterator __last)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  			  _ForwardIterator>)
    __glibcxx_requires_valid_range(__first, __middle);
    __glibcxx_requires_valid_range(__middle, __last);

    typedef typename iterator_traits<_ForwardIterator>::iterator_category
  _IterType;
    std::__rotate(__first, __middle, __last, _IterType());
  }

/**
 *  @brief Copy a sequence, rotating its elements.
 *  @ingroup mutating_algorithms
 *  @param  __first   A forward iterator.
 *  @param  __middle  A forward iterator.
 *  @param  __last    A forward iterator.
 *  @param  __result  An output iterator.
 *  @return   An iterator designating the end of the resulting sequence.
 *
 *  Copies the elements of the range @p [__first,__last) to the
 *  range beginning at @result, rotating the copied elements by 
 *  @p (__middle-__first) positions so that the element at @p __middle
 *  is moved to @p __result, the element at @p __middle+1 is moved
 *  to @p __result+1 and so on for each element in the range @p
 *  [__first,__last).
 *
 *  Performs 
 *  @p *(__result+(n+(__last-__middle))%(__last-__first))=*(__first+n)
 *  for each @p n in the range @p [0,__last-__first).
*/
template<typename _ForwardIterator, typename _OutputIterator>
  _OutputIterator
  rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
              _ForwardIterator __last, _OutputIterator __result)
  {
    // concept requirements
    __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
    __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
  	typename iterator_traits<_ForwardIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __middle);
    __glibcxx_requires_valid_range(__middle, __last);

    return std::copy(__first, __middle,
                     std::copy(__middle, __last, __result));
  }

/// This is a helper function...
template<typename _ForwardIterator, typename _Predicate>
  _ForwardIterator
  __partition(_ForwardIterator __first, _ForwardIterator __last,
  	_Predicate __pred, forward_iterator_tag)
  {
    if (__first == __last)
  return __first;

    while (__pred(*__first))
  if (++__first == __last)
    return __first;

    _ForwardIterator __next = __first;

    while (++__next != __last)
  if (__pred(*__next))
    {
      std::iter_swap(__first, __next);
      ++__first;
    }

    return __first;
  }

/// This is a helper function...
template<typename _BidirectionalIterator, typename _Predicate>
  _BidirectionalIterator
  __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
  	_Predicate __pred, bidirectional_iterator_tag)
  {
    while (true)
  {
    while (true)
      if (__first == __last)
        return __first;
      else if (__pred(*__first))
        ++__first;
      else
        break;
    --__last;
    while (true)
      if (__first == __last)
        return __first;
      else if (!bool(__pred(*__last)))
        --__last;
      else
        break;
    std::iter_swap(__first, __last);
    ++__first;
  }
  }

// partition

/// This is a helper function...
/// Requires __len != 0 and !__pred(*__first),
/// same as __stable_partition_adaptive.
template<typename _ForwardIterator, typename _Predicate, typename _Distance>
  _ForwardIterator
  __inplace_stable_partition(_ForwardIterator __first,
  		       _Predicate __pred, _Distance __len)
  {
    if (__len == 1)
  return __first;
    _ForwardIterator __middle = __first;
    std::advance(__middle, __len / 2);
    _ForwardIterator __left_split =
  std::__inplace_stable_partition(__first, __pred, __len / 2);
    // Advance past true-predicate values to satisfy this
    // function's preconditions.
    _Distance __right_len = __len - __len / 2;
    _ForwardIterator __right_split =
  std::__find_if_not_n(__middle, __right_len, __pred);
    if (__right_len)
  __right_split = std::__inplace_stable_partition(__middle,
  						__pred,
  						__right_len);
    std::rotate(__left_split, __middle, __right_split);
    std::advance(__left_split, std::distance(__middle, __right_split));
    return __left_split;
  }

/// This is a helper function...
/// Requires __first != __last and !__pred(*__first)
/// and __len == distance(__first, __last).
///
/// !__pred(*__first) allows us to guarantee that we don't
/// move-assign an element onto itself.
template<typename _ForwardIterator, typename _Pointer, typename _Predicate,
     typename _Distance>
  _ForwardIterator
  __stable_partition_adaptive(_ForwardIterator __first,
  			_ForwardIterator __last,
  			_Predicate __pred, _Distance __len,
  			_Pointer __buffer,
  			_Distance __buffer_size)
  {
    if (__len <= __buffer_size)
  {
    _ForwardIterator __result1 = __first;
    _Pointer __result2 = __buffer;
    // The precondition guarantees that !__pred(*__first), so
    // move that element to the buffer before starting the loop.
    // This ensures that we only call __pred once per element.
    *__result2 = _GLIBCXX_MOVE(*__first);
    ++__result2;
    ++__first;
    for (; __first != __last; ++__first)
      if (__pred(*__first))
        {
  	*__result1 = _GLIBCXX_MOVE(*__first);
  	++__result1;
        }
      else
        {
  	*__result2 = _GLIBCXX_MOVE(*__first);
  	++__result2;
        }
    _GLIBCXX_MOVE3(__buffer, __result2, __result1);
    return __result1;
  }
    else
  {
    _ForwardIterator __middle = __first;
    std::advance(__middle, __len / 2);
    _ForwardIterator __left_split =
      std::__stable_partition_adaptive(__first, __middle, __pred,
  				     __len / 2, __buffer,
  				     __buffer_size);
    // Advance past true-predicate values to satisfy this
    // function's preconditions.
    _Distance __right_len = __len - __len / 2;
    _ForwardIterator __right_split =
      std::__find_if_not_n(__middle, __right_len, __pred);
    if (__right_len)
      __right_split =
        std::__stable_partition_adaptive(__right_split, __last, __pred,
  				       __right_len,
  				       __buffer, __buffer_size);
    std::rotate(__left_split, __middle, __right_split);
    std::advance(__left_split, std::distance(__middle, __right_split));
    return __left_split;
  }
  }

/**
 *  @brief Move elements for which a predicate is true to the beginning
 *         of a sequence, preserving relative ordering.
 *  @ingroup mutating_algorithms
 *  @param  __first   A forward iterator.
 *  @param  __last    A forward iterator.
 *  @param  __pred    A predicate functor.
 *  @return  An iterator @p middle such that @p __pred(i) is true for each
 *  iterator @p i in the range @p [first,middle) and false for each @p i
 *  in the range @p [middle,last).
 *
 *  Performs the same function as @p partition() with the additional
 *  guarantee that the relative ordering of elements in each group is
 *  preserved, so any two elements @p x and @p y in the range
 *  @p [__first,__last) such that @p __pred(x)==__pred(y) will have the same
 *  relative ordering after calling @p stable_partition().
*/
template<typename _ForwardIterator, typename _Predicate>
  _ForwardIterator
  stable_partition(_ForwardIterator __first, _ForwardIterator __last,
  	     _Predicate __pred)
  {
    // concept requirements
    __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
  			  _ForwardIterator>)
    __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
      typename iterator_traits<_ForwardIterator>::value_type>)
    __glibcxx_requires_valid_range(__first, __last);

    __first = std::__find_if_not(__first, __last, __pred);

    if (__first == __last)
  return __first;
    else
  {
    typedef typename iterator_traits<_ForwardIterator>::value_type
      _ValueType;
    typedef typename iterator_traits<_ForwardIterator>::difference_type
      _DistanceType;

    _Temporary_buffer<_ForwardIterator, _ValueType> __buf(__first,
  							__last);
  if (__buf.size() > 0)
    return
      std::__stable_partition_adaptive(__first, __last, __pred,
  				  _DistanceType(__buf.requested_size()),
  				  __buf.begin(),
  				  _DistanceType(__buf.size()));
  else
    return
      std::__inplace_stable_partition(__first, __pred,
  				 _DistanceType(__buf.requested_size()));
  }
  }

/// This is a helper function for the sort routines.
template<typename _RandomAccessIterator>
  void
  __heap_select(_RandomAccessIterator __first,
  	  _RandomAccessIterator __middle,
  	  _RandomAccessIterator __last)
  {
    std::make_heap(__first, __middle);
    for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
  if (*__i < *__first)
    std::__pop_heap(__first, __middle, __i);
  }

/// This is a helper function for the sort routines.
template<typename _RandomAccessIterator, typename _Compare>
  void
  __heap_select(_RandomAccessIterator __first,
  	  _RandomAccessIterator __middle,
  	  _RandomAccessIterator __last, _Compare __comp)
  {
    std::make_heap(__first, __middle, __comp);
    for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
  if (__comp(*__i, *__first))
    std::__pop_heap(__first, __middle, __i, __comp);
  }

// partial_sort

/**
 *  @brief Copy the smallest elements of a sequence.
 *  @ingroup sorting_algorithms
2024/7/15 21:07
加载中...