stl_numeric.h (iota): Add in C++0x mode.
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 27 Jun 2008 10:47:27 +0000 (10:47 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 27 Jun 2008 10:47:27 +0000 (10:47 +0000)
2008-06-27  Paolo Carlini  <paolo.carlini@oracle.com>

* include/bits/stl_numeric.h (iota): Add in C++0x mode.
* testsuite/util/testsuite_character.h (pod_int): Add operator++
in C++0x mode.
* testsuite/util/testsuite_api.h (NonDefaultConstructible): Likewise.
* testsuite/26_numerics/iota/1.cc: New.
* testsuite/26_numerics/iota/requirements/explicit_instantiation/
2.cc: Likewise.
* testsuite/26_numerics/iota/requirements/explicit_instantiation/
pod.cc: Likewise.

* include/ext/algorithm: Do not fiddle with the legacy headers.

* testsuite/26_numerics/partial_sum/1.cc: Minor changes, comments,
style.
* testsuite/26_numerics/accumulate/1.cc: Likewise.
* testsuite/26_numerics/adjacent_difference/1.cc: Likewise.
* testsuite/26_numerics/inner_product/1.cc: Likewise.

From-SVN: r137174

12 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_numeric.h
libstdc++-v3/include/ext/algorithm
libstdc++-v3/testsuite/26_numerics/accumulate/1.cc
libstdc++-v3/testsuite/26_numerics/adjacent_difference/1.cc
libstdc++-v3/testsuite/26_numerics/inner_product/1.cc
libstdc++-v3/testsuite/26_numerics/iota/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/partial_sum/1.cc
libstdc++-v3/testsuite/util/testsuite_api.h
libstdc++-v3/testsuite/util/testsuite_character.h

index 87331b9..b5191e8 100644 (file)
@@ -1,3 +1,23 @@
+2008-06-27  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/bits/stl_numeric.h (iota): Add in C++0x mode.
+       * testsuite/util/testsuite_character.h (pod_int): Add operator++
+       in C++0x mode.
+       * testsuite/util/testsuite_api.h (NonDefaultConstructible): Likewise.
+       * testsuite/26_numerics/iota/1.cc: New.
+       * testsuite/26_numerics/iota/requirements/explicit_instantiation/
+       2.cc: Likewise.
+       * testsuite/26_numerics/iota/requirements/explicit_instantiation/
+       pod.cc: Likewise.
+
+       * include/ext/algorithm: Do not fiddle with the legacy headers.
+
+       * testsuite/26_numerics/partial_sum/1.cc: Minor changes, comments,
+       style.
+       * testsuite/26_numerics/accumulate/1.cc: Likewise.
+       * testsuite/26_numerics/adjacent_difference/1.cc: Likewise.
+       * testsuite/26_numerics/inner_product/1.cc: Likewise.
+
 2008-06-26  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * include/bits/stl_algo.h (partition_copy): Add in C++0x mode.
index 3940e4a..c861226 100644 (file)
@@ -1,6 +1,6 @@
 // Numeric functions implementation -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 #include <bits/concept_check.h>
 #include <debug/debug.h>
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+  /**
+   *  @brief  Create a range of sequentially increasing values.
+   *
+   *  For each element in the range @p [first,last) assigns @p value and
+   *  increments @p value as if by @p ++value.
+   *
+   *  @param  first  Start of range.
+   *  @param  last  End of range.
+   *  @param  value  Starting value.
+   *  @return  Nothing.
+   */
+  template<typename _ForwardIterator, typename _Tp>
+    void
+    iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
+    {
+      // concept requirements
+      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
+                                 _ForwardIterator>)
+      __glibcxx_function_requires(_ConvertibleConcept<_Tp,
+           typename iterator_traits<_ForwardIterator>::value_type>)
+      __glibcxx_requires_valid_range(__first, __last);
+
+      for (; __first != __last; ++__first)
+       {
+         *__first = __value;
+         ++__value;
+       }
+    }
+
+_GLIBCXX_END_NAMESPACE
+
+#endif
+
 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
 
   /**
@@ -164,7 +201,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
    *  @return  The final inner product.
    */
   template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
-           typename _BinaryOperation1, typename _BinaryOperation2>
+          typename _BinaryOperation1, typename _BinaryOperation2>
     inline _Tp
     inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
                  _InputIterator2 __first2, _Tp __init,
index 5a24b7e..2af2cb1 100644 (file)
@@ -1,6 +1,6 @@
 // Algorithm extensions -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -428,10 +428,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
                             __out_last - __out_first);
     }
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-  using std::is_heap;
-  using std::is_sorted;
-#else
   /**
    *  This is an SGI extension.
    *  @ingroup SGIextensions
@@ -527,7 +523,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
          return false;
       return true;
     }
-#endif
 
 _GLIBCXX_END_NAMESPACE
 
index 046532d..22a67fe 100644 (file)
@@ -1,4 +1,5 @@
-// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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
@@ -48,7 +49,7 @@ test02()
 int
 main()
 {
-    test01();
-    test02();
-    return 0;
+  test01();
+  test02();
+  return 0;
 }
index 5501f3f..e53e279 100644 (file)
@@ -1,4 +1,5 @@
-// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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
@@ -16,7 +17,6 @@
 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 // USA.
 
-// 26.4.3 [lib.partial.sum]
 // 26.4.4 [lib.adjacent.difference]
 
 #include <algorithm>
@@ -41,6 +41,6 @@ test01()
 int
 main()
 {
-    test01();
-    return 0;
+  test01();
+  return 0;
 }
index d63c1d9..6c44fae 100644 (file)
@@ -1,4 +1,5 @@
-// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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
@@ -50,7 +51,7 @@ test02()
 int
 main()
 {
-    test01();
-    test02();
-    return 0;
+  test01();
+  test02();
+  return 0;
 }
diff --git a/libstdc++-v3/testsuite/26_numerics/iota/1.cc b/libstdc++-v3/testsuite/26_numerics/iota/1.cc
new file mode 100644 (file)
index 0000000..2c747c1
--- /dev/null
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2008-06-27  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.
+
+#include <numeric>
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+int A[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+int C[] = {-9, -8, -7, -6, -5, -4, -3, -2, -1};
+const int N = sizeof(A) / sizeof(int);
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::iota(A, A + N, 1);
+  VERIFY( std::equal(A, A + N, B) );
+
+  std::iota(A, A + N, -9);
+  VERIFY( std::equal(A, A + N, C) );
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc
new file mode 100644 (file)
index 0000000..fd0eba8
--- /dev/null
@@ -0,0 +1,42 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// 2008-06-27  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 <numeric>
+#include <testsuite_api.h>
+
+namespace std
+{
+  typedef __gnu_test::NonDefaultConstructible  value_type;
+  typedef value_type*          iterator_type;
+
+  template void iota(iterator_type, iterator_type, value_type);
+} 
diff --git a/libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc b/libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc
new file mode 100644 (file)
index 0000000..a24ac95
--- /dev/null
@@ -0,0 +1,42 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// 2008-06-27  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 <numeric>
+#include <testsuite_character.h>
+
+namespace std
+{
+  typedef __gnu_test::pod_int  value_type;
+  typedef value_type*          iterator_type;
+
+  template void iota(iterator_type, iterator_type, value_type);
+} 
index ac33691..c972b31 100644 (file)
@@ -1,4 +1,5 @@
-// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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
@@ -17,7 +18,6 @@
 // USA.
 
 // 26.4.3 [lib.partial.sum]
-// 26.4.4 [lib.adjacent.difference]
 
 #include <algorithm>
 #include <numeric>
index 658e2ad..cbb606c 100644 (file)
@@ -84,6 +84,13 @@ namespace __gnu_test
   {
     NonDefaultConstructible(int) { }
     NonDefaultConstructible(const NonDefaultConstructible&) { }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    // For std::iota.
+    NonDefaultConstructible&
+    operator++()
+    { return *this; }
+#endif
   };
  
   // See: 20.1.1 Template argument requirements.
index e9dde65..2aa0bc7 100644 (file)
@@ -3,7 +3,8 @@
 // Testing character type and state type with char_traits and codecvt
 // specializations for the C++ library testsuite.
 //
-// Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+// Copyright (C) 2003, 2004, 2005, 2006, 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
@@ -44,8 +45,18 @@ namespace __gnu_test
   struct pod_int
   {
     int value;
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+    // For std::iota.
+    pod_int&
+    operator++()
+    {
+      ++value;
+      return *this;
+    }
+#endif
   };
-  
+
   // For 20.1 requirements for instantiable type: equality comparable
   // and less than comparable.
   inline bool