stl_algo.h (remove_if): Cast __pred result to bool.
2008-06-24 Paolo Carlini <paolo.carlini@oracle.com> * include/bits/stl_algo.h (remove_if): Cast __pred result to bool. (copy_if): Add, per N2666. * testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/ 2.cc: New. * testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/ pod.cc: Likewise. * testsuite/25_algorithms/headers/algorithm/synopsis.cc: Update. From-SVN: r137080
This commit is contained in:
parent
db16ca8c7f
commit
a057a4f13b
5 changed files with 157 additions and 3 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2008-06-24 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
* include/bits/stl_algo.h (remove_if): Cast __pred result to bool.
|
||||||
|
(copy_if): Add, per N2666.
|
||||||
|
* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/
|
||||||
|
2.cc: New.
|
||||||
|
* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/
|
||||||
|
pod.cc: Likewise.
|
||||||
|
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Update.
|
||||||
|
|
||||||
2008-06-24 Paolo Carlini <paolo.carlini@oracle.com>
|
2008-06-24 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
Chalathip Thumkanon <chalathip@gmail.com>
|
Chalathip Thumkanon <chalathip@gmail.com>
|
||||||
|
|
||||||
|
|
|
@ -712,7 +712,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
* @return An iterator designating the end of the resulting sequence.
|
* @return An iterator designating the end of the resulting sequence.
|
||||||
*
|
*
|
||||||
* Copies each element in the range @p [first,last) for which
|
* Copies each element in the range @p [first,last) for which
|
||||||
* @p pred returns true to the range beginning at @p result.
|
* @p pred returns false to the range beginning at @p result.
|
||||||
*
|
*
|
||||||
* remove_copy_if() is stable, so the relative order of elements that are
|
* remove_copy_if() is stable, so the relative order of elements that are
|
||||||
* copied is unchanged.
|
* copied is unchanged.
|
||||||
|
@ -740,6 +740,45 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
return __result;
|
return __result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
|
/**
|
||||||
|
* @brief Copy the elements of a sequence for which a predicate is true.
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove elements from a sequence.
|
* @brief Remove elements from a sequence.
|
||||||
* @param first An input iterator.
|
* @param first An input iterator.
|
||||||
|
@ -816,7 +855,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
_ForwardIterator __result = __first;
|
_ForwardIterator __result = __first;
|
||||||
++__first;
|
++__first;
|
||||||
for(; __first != __last; ++__first)
|
for(; __first != __last; ++__first)
|
||||||
if(!__pred(*__first))
|
if(!bool(__pred(*__first)))
|
||||||
{
|
{
|
||||||
*__result = _GLIBCXX_MOVE(*__first);
|
*__result = _GLIBCXX_MOVE(*__first);
|
||||||
++__result;
|
++__result;
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
// { dg-do compile }
|
||||||
|
// { dg-options "-std=gnu++0x" }
|
||||||
|
|
||||||
|
// 2008-06-24 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2008 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 2, 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.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// As a special exception, you may use this file as part of a free software
|
||||||
|
// library without restriction. Specifically, if other files instantiate
|
||||||
|
// templates or use macros or inline functions from this file, or you compile
|
||||||
|
// this file and link it with other files to produce an executable, this
|
||||||
|
// file does not by itself cause the resulting executable to be covered by
|
||||||
|
// the GNU General Public License. This exception does not however
|
||||||
|
// invalidate any other reasons why the executable file might be covered by
|
||||||
|
// the GNU General Public License.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <testsuite_api.h>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
using __gnu_test::NonDefaultConstructible;
|
||||||
|
|
||||||
|
typedef NonDefaultConstructible value_type;
|
||||||
|
typedef value_type* iterator_type;
|
||||||
|
typedef std::pointer_to_unary_function<value_type, bool> predicate_type;
|
||||||
|
|
||||||
|
template iterator_type copy_if(iterator_type, iterator_type,
|
||||||
|
iterator_type, predicate_type);
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
// { dg-do compile }
|
||||||
|
// { dg-options "-std=gnu++0x" }
|
||||||
|
|
||||||
|
// 2008-06-24 Paolo Carlini <paolo.carlini@oracle.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2008 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 2, 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.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this library; see the file COPYING. If not, write to the Free
|
||||||
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
// USA.
|
||||||
|
|
||||||
|
// As a special exception, you may use this file as part of a free software
|
||||||
|
// library without restriction. Specifically, if other files instantiate
|
||||||
|
// templates or use macros or inline functions from this file, or you compile
|
||||||
|
// this file and link it with other files to produce an executable, this
|
||||||
|
// file does not by itself cause the resulting executable to be covered by
|
||||||
|
// the GNU General Public License. This exception does not however
|
||||||
|
// invalidate any other reasons why the executable file might be covered by
|
||||||
|
// the GNU General Public License.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <testsuite_character.h>
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
using __gnu_test::pod_int;
|
||||||
|
|
||||||
|
typedef pod_int value_type;
|
||||||
|
typedef value_type* iterator_type;
|
||||||
|
typedef std::pointer_to_unary_function<value_type, bool> predicate_type;
|
||||||
|
|
||||||
|
template iterator_type copy_if(iterator_type, iterator_type,
|
||||||
|
iterator_type, predicate_type);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
// { dg-do compile }
|
// { dg-do compile }
|
||||||
|
|
||||||
// Copyright (C) 2007 Free Software Foundation, Inc.
|
// Copyright (C) 2007, 2008 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// 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
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -115,6 +115,12 @@ namespace std
|
||||||
void
|
void
|
||||||
swap(_Tp&, _Tp& b);
|
swap(_Tp&, _Tp& b);
|
||||||
|
|
||||||
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
|
template<typename _Tp, size_t _Nm>
|
||||||
|
void
|
||||||
|
swap(_Tp (&)[_Nm], _Tp (&)[_Nm]);
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename _FIter1, typename _FIter2>
|
template<typename _FIter1, typename _FIter2>
|
||||||
_FIter2
|
_FIter2
|
||||||
swap_ranges(_FIter1 first1, _FIter1, _FIter2);
|
swap_ranges(_FIter1 first1, _FIter1, _FIter2);
|
||||||
|
@ -180,6 +186,12 @@ namespace std
|
||||||
_OIter
|
_OIter
|
||||||
remove_copy_if(_IIter, _IIter, _OIter, _Predicate);
|
remove_copy_if(_IIter, _IIter, _OIter, _Predicate);
|
||||||
|
|
||||||
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||||
|
template<typename _IIter, typename _OIter, typename _Predicate>
|
||||||
|
_OIter
|
||||||
|
copy_if(_IIter, _IIter, _OIter, _Predicate);
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename _FIter>
|
template<typename _FIter>
|
||||||
_FIter
|
_FIter
|
||||||
unique(_FIter, _FIter);
|
unique(_FIter, _FIter);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue