OSDN Git Service

2008-06-24 Paolo Carlini <paolo.carlini@oracle.com>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 24 Jun 2008 18:02:36 +0000 (18:02 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 24 Jun 2008 18:02:36 +0000 (18:02 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137080 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/pod.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/headers/algorithm/synopsis.cc

index 18af91c..ccb1e1d 100644 (file)
@@ -1,4 +1,14 @@
 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>
            Chalathip Thumkanon  <chalathip@gmail.com>
 
        PR libstdc++/36612
index 549c0ca..6b1e8a5 100644 (file)
@@ -712,7 +712,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
    *  @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.
+   *  @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.
@@ -740,6 +740,45 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       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.
    *  @param  first  An input iterator.
@@ -816,7 +855,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       _ForwardIterator __result = __first;
       ++__first;
       for(; __first != __last; ++__first)
-        if(!__pred(*__first))
+        if(!bool(__pred(*__first)))
           {
             *__result = _GLIBCXX_MOVE(*__first);
             ++__result;
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/2.cc
new file mode 100644 (file)
index 0000000..b710506
--- /dev/null
@@ -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);
+} 
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/pod.cc
new file mode 100644 (file)
index 0000000..7433367
--- /dev/null
@@ -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);
+} 
index 4939ebf..87487b3 100644 (file)
@@ -1,6 +1,6 @@
 // { 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
 // software; you can redistribute it and/or modify it under the
@@ -115,6 +115,12 @@ namespace std
     void 
     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>
     _FIter2 
     swap_ranges(_FIter1 first1, _FIter1, _FIter2);
@@ -180,6 +186,12 @@ namespace std
     _OIter 
     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>
     _FIter 
     unique(_FIter, _FIter);