From fa52081d8605854c0c9eaf9cb5266fe685f4a457 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 27 Jun 2008 10:47:27 +0000 Subject: [PATCH] stl_numeric.h (iota): Add in C++0x mode. 2008-06-27 Paolo Carlini * 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 --- libstdc++-v3/ChangeLog | 20 ++++++++ libstdc++-v3/include/bits/stl_numeric.h | 41 +++++++++++++++- libstdc++-v3/include/ext/algorithm | 7 +-- .../testsuite/26_numerics/accumulate/1.cc | 9 ++-- .../26_numerics/adjacent_difference/1.cc | 8 +-- .../testsuite/26_numerics/inner_product/1.cc | 9 ++-- libstdc++-v3/testsuite/26_numerics/iota/1.cc | 49 +++++++++++++++++++ .../requirements/explicit_instantiation/2.cc | 42 ++++++++++++++++ .../explicit_instantiation/pod.cc | 42 ++++++++++++++++ .../testsuite/26_numerics/partial_sum/1.cc | 4 +- libstdc++-v3/testsuite/util/testsuite_api.h | 7 +++ .../testsuite/util/testsuite_character.h | 15 +++++- 12 files changed, 229 insertions(+), 24 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/iota/1.cc create mode 100644 libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc create mode 100644 libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 87331b9b56e..b5191e8385a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2008-06-27 Paolo Carlini + + * 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 * include/bits/stl_algo.h (partition_copy): Add in C++0x mode. diff --git a/libstdc++-v3/include/bits/stl_numeric.h b/libstdc++-v3/include/bits/stl_numeric.h index 3940e4aa970..c86122679da 100644 --- a/libstdc++-v3/include/bits/stl_numeric.h +++ b/libstdc++-v3/include/bits/stl_numeric.h @@ -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 #include +#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 + 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 _BinaryOperation1, typename _BinaryOperation2> inline _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init, diff --git a/libstdc++-v3/include/ext/algorithm b/libstdc++-v3/include/ext/algorithm index 5a24b7e6f48..2af2cb1cb36 100644 --- a/libstdc++-v3/include/ext/algorithm +++ b/libstdc++-v3/include/ext/algorithm @@ -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 diff --git a/libstdc++-v3/testsuite/26_numerics/accumulate/1.cc b/libstdc++-v3/testsuite/26_numerics/accumulate/1.cc index 046532debef..22a67fe8fea 100644 --- a/libstdc++-v3/testsuite/26_numerics/accumulate/1.cc +++ b/libstdc++-v3/testsuite/26_numerics/accumulate/1.cc @@ -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; } diff --git a/libstdc++-v3/testsuite/26_numerics/adjacent_difference/1.cc b/libstdc++-v3/testsuite/26_numerics/adjacent_difference/1.cc index 5501f3f9fa6..e53e279cf27 100644 --- a/libstdc++-v3/testsuite/26_numerics/adjacent_difference/1.cc +++ b/libstdc++-v3/testsuite/26_numerics/adjacent_difference/1.cc @@ -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 @@ -41,6 +41,6 @@ test01() int main() { - test01(); - return 0; + test01(); + return 0; } diff --git a/libstdc++-v3/testsuite/26_numerics/inner_product/1.cc b/libstdc++-v3/testsuite/26_numerics/inner_product/1.cc index d63c1d91099..6c44fae3c88 100644 --- a/libstdc++-v3/testsuite/26_numerics/inner_product/1.cc +++ b/libstdc++-v3/testsuite/26_numerics/inner_product/1.cc @@ -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 index 00000000000..2c747c13e96 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/iota/1.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } + +// 2008-06-27 Paolo Carlini + +// 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 +#include +#include + +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 index 00000000000..fd0eba869a6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/2.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2008-06-27 Paolo Carlini + +// 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 +#include + +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 index 00000000000..a24ac95c894 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/iota/requirements/explicit_instantiation/pod.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 2008-06-27 Paolo Carlini + +// 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 +#include + +namespace std +{ + typedef __gnu_test::pod_int value_type; + typedef value_type* iterator_type; + + template void iota(iterator_type, iterator_type, value_type); +} diff --git a/libstdc++-v3/testsuite/26_numerics/partial_sum/1.cc b/libstdc++-v3/testsuite/26_numerics/partial_sum/1.cc index ac336916656..c972b31651a 100644 --- a/libstdc++-v3/testsuite/26_numerics/partial_sum/1.cc +++ b/libstdc++-v3/testsuite/26_numerics/partial_sum/1.cc @@ -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 #include diff --git a/libstdc++-v3/testsuite/util/testsuite_api.h b/libstdc++-v3/testsuite/util/testsuite_api.h index 658e2ad168c..cbb606c42a8 100644 --- a/libstdc++-v3/testsuite/util/testsuite_api.h +++ b/libstdc++-v3/testsuite/util/testsuite_api.h @@ -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. diff --git a/libstdc++-v3/testsuite/util/testsuite_character.h b/libstdc++-v3/testsuite/util/testsuite_character.h index e9dde65c2f3..2aa0bc72e53 100644 --- a/libstdc++-v3/testsuite/util/testsuite_character.h +++ b/libstdc++-v3/testsuite/util/testsuite_character.h @@ -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 -- 2.30.2