* [v3] Add std::iota
@ 2008-06-27 10:53 Paolo Carlini
0 siblings, 0 replies; only message in thread
From: Paolo Carlini @ 2008-06-27 10:53 UTC (permalink / raw)
To: Gcc Patch List; +Cc: libstdc++
[-- Attachment #1: Type: text/plain, Size: 77 bytes --]
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
//////////////////
[-- Attachment #2: CL_iota.txt --]
[-- Type: text/plain, Size: 787 bytes --]
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.
[-- Attachment #3: patch_iota.txt --]
[-- Type: text/plain, Size: 13138 bytes --]
Index: include/ext/algorithm
===================================================================
--- include/ext/algorithm (revision 137173)
+++ include/ext/algorithm (working copy)
@@ -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 @@
__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 @@
return false;
return true;
}
-#endif
_GLIBCXX_END_NAMESPACE
Index: include/bits/stl_numeric.h
===================================================================
--- include/bits/stl_numeric.h (revision 137173)
+++ include/bits/stl_numeric.h (working copy)
@@ -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
@@ -65,6 +65,43 @@
#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 @@
* @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: testsuite/26_numerics/partial_sum/1.cc
===================================================================
--- testsuite/26_numerics/partial_sum/1.cc (revision 137173)
+++ testsuite/26_numerics/partial_sum/1.cc (working copy)
@@ -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: testsuite/26_numerics/accumulate/1.cc
===================================================================
--- testsuite/26_numerics/accumulate/1.cc (revision 137173)
+++ testsuite/26_numerics/accumulate/1.cc (working copy)
@@ -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 @@
int
main()
{
- test01();
- test02();
- return 0;
+ test01();
+ test02();
+ return 0;
}
Index: testsuite/26_numerics/adjacent_difference/1.cc
===================================================================
--- testsuite/26_numerics/adjacent_difference/1.cc (revision 137173)
+++ testsuite/26_numerics/adjacent_difference/1.cc (working copy)
@@ -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 @@
int
main()
{
- test01();
- return 0;
+ test01();
+ return 0;
}
Index: testsuite/26_numerics/inner_product/1.cc
===================================================================
--- testsuite/26_numerics/inner_product/1.cc (revision 137173)
+++ testsuite/26_numerics/inner_product/1.cc (working copy)
@@ -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 @@
int
main()
{
- test01();
- test02();
- return 0;
+ test01();
+ test02();
+ return 0;
}
Index: testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc
===================================================================
--- testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc (revision 0)
+++ testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc (revision 0)
@@ -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);
+}
Index: testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc
===================================================================
--- testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc (revision 0)
+++ testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc (revision 0)
@@ -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: testsuite/26_numerics/iota/1.cc
===================================================================
--- testsuite/26_numerics/iota/1.cc (revision 0)
+++ testsuite/26_numerics/iota/1.cc (revision 0)
@@ -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;
+}
Index: testsuite/util/testsuite_character.h
===================================================================
--- testsuite/util/testsuite_character.h (revision 137173)
+++ testsuite/util/testsuite_character.h (working copy)
@@ -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 @@
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
Index: testsuite/util/testsuite_api.h
===================================================================
--- testsuite/util/testsuite_api.h (revision 137173)
+++ testsuite/util/testsuite_api.h (working copy)
@@ -84,6 +84,13 @@
{
NonDefaultConstructible(int) { }
NonDefaultConstructible(const NonDefaultConstructible&) { }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ // For std::iota.
+ NonDefaultConstructible&
+ operator++()
+ { return *this; }
+#endif
};
// See: 20.1.1 Template argument requirements.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-06-27 10:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-27 10:53 [v3] Add std::iota Paolo Carlini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).