OSDN Git Service

2009-09-01 Chris Jefferson <chris@bubblescope.net>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 Sep 2009 10:19:11 +0000 (10:19 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 1 Sep 2009 10:19:11 +0000 (10:19 +0000)
    Paolo Carlini  <paolo.carlini@oracle.com>

* testsuite/util/testsuite_rvalref.h: Remove obsolete macro using
_GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING.
* testsuite/20_util/specialized_algorithms/uninitialized_copy_n/
move_iterators/1.cc: Adjust, do not define
_GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING.
* testsuite/20_util/specialized_algorithms/uninitialized_copy/
move_iterators/1.cc: Likewise.
* testsuite/25_algorithms/copy_n/move_iterators/1.cc: Likewise.
* testsuite/25_algorithms/move/1.cc: Likewise.
* testsuite/25_algorithms/move_backward/1.cc: Likewise.
* testsuite/25_algorithms/copy_backward/move_iterators/1.cc: Likewise.
* testsuite/25_algorithms/copy/move_iterators/1.cc: Likewise.
* testsuite/25_algorithms/heap/moveable.cc: Likewise.
* testsuite/25_algorithms/partial_sort/moveable.cc: Likewise; add
test for predicated test.
* testsuite/25_algorithms/sort/moveable.cc: Likewise.
* testsuite/25_algorithms/nth_element/moveable.cc: Add test
for predicated version.
* testsuite/25_algorithms/unique/moveable.cc: Likewise.

* testsuite/25_algorithms/inplace_merge/1.cc (S::operator<): Fix,
enable test2 and test3.

* testsuite/util/testsuite_iterators.h (operator=): Fix invalid
moving bug in C++0x mode.

* testsuite/25_algorithms/random_shuffle/moveable.cc: New.
* testsuite/25_algorithms/prev_permutation/moveable.cc: Likewise.
* testsuite/25_algorithms/next_permutation/moveable.cc: Likewise.
* testsuite/25_algorithms/heap/moveable2.cc: Likewise.

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

20 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy/move_iterators/1.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_copy_n/move_iterators/1.cc
libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/1.cc
libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/1.cc
libstdc++-v3/testsuite/25_algorithms/copy_n/move_iterators/1.cc
libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc
libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/inplace_merge/1.cc
libstdc++-v3/testsuite/25_algorithms/move/1.cc
libstdc++-v3/testsuite/25_algorithms/move_backward/1.cc
libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc
libstdc++-v3/testsuite/25_algorithms/partial_sort/moveable.cc
libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc
libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc
libstdc++-v3/testsuite/util/testsuite_iterators.h
libstdc++-v3/testsuite/util/testsuite_rvalref.h

index fb0d38d..5d9031e 100644 (file)
@@ -1,3 +1,37 @@
+2009-09-01  Chris Jefferson  <chris@bubblescope.net>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * testsuite/util/testsuite_rvalref.h: Remove obsolete macro using
+       _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING.
+       * testsuite/20_util/specialized_algorithms/uninitialized_copy_n/
+       move_iterators/1.cc: Adjust, do not define
+       _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING.
+       * testsuite/20_util/specialized_algorithms/uninitialized_copy/
+       move_iterators/1.cc: Likewise.
+       * testsuite/25_algorithms/copy_n/move_iterators/1.cc: Likewise.
+       * testsuite/25_algorithms/move/1.cc: Likewise.
+       * testsuite/25_algorithms/move_backward/1.cc: Likewise.
+       * testsuite/25_algorithms/copy_backward/move_iterators/1.cc: Likewise.
+       * testsuite/25_algorithms/copy/move_iterators/1.cc: Likewise.
+       * testsuite/25_algorithms/heap/moveable.cc: Likewise.
+       * testsuite/25_algorithms/partial_sort/moveable.cc: Likewise; add
+       test for predicated test.
+       * testsuite/25_algorithms/sort/moveable.cc: Likewise.
+       * testsuite/25_algorithms/nth_element/moveable.cc: Add test
+       for predicated version.
+       * testsuite/25_algorithms/unique/moveable.cc: Likewise.
+
+       * testsuite/25_algorithms/inplace_merge/1.cc (S::operator<): Fix,
+       enable test2 and test3.
+
+       * testsuite/util/testsuite_iterators.h (operator=): Fix invalid
+       moving bug in C++0x mode.
+
+       * testsuite/25_algorithms/random_shuffle/moveable.cc: New.
+       * testsuite/25_algorithms/prev_permutation/moveable.cc: Likewise.
+       * testsuite/25_algorithms/next_permutation/moveable.cc: Likewise.
+       * testsuite/25_algorithms/heap/moveable2.cc: Likewise.
+
 2009-08-31  Uros Bizjak  <ubizjak@gmail.com>
            Kaz Kojima  <kkojima@gcc.gnu.org>
 
index c97a486..e07c492 100644 (file)
@@ -18,7 +18,6 @@
 // <http://www.gnu.org/licenses/>.
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define  _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <iterator>
index 0b8b70b..aaf5006 100644 (file)
@@ -18,7 +18,6 @@
 // <http://www.gnu.org/licenses/>.
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define  _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <iterator>
index fedb03a..6c22ba6 100644 (file)
@@ -20,7 +20,6 @@
 // <http://www.gnu.org/licenses/>.
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define  _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <iterator>
index 10456c9..0a69659 100644 (file)
@@ -22,7 +22,6 @@
 // 25.3.6 Heap operations [lib.alg.heap.operations]
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define  _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <testsuite_hooks.h>
@@ -40,11 +39,11 @@ using __gnu_test::rvalstruct;
 typedef test_container<rvalstruct, random_access_iterator_wrapper> container;
 typedef test_container<int, random_access_iterator_wrapper> container_ref;
 
-bool test __attribute__((unused)) = true;
-
 void 
 check_make(int* array, int length)
 {
+  bool test __attribute__((unused)) = true;
+
   rvalstruct makeheap[9];
   int        makeheap_ref[9];
   std::copy(array, array + length, makeheap);
@@ -63,6 +62,8 @@ check_make(int* array, int length)
 void
 check_pop(int* array, int length)
 {
+  bool test __attribute__((unused)) = true;
+
   rvalstruct popheap[9];
   int        popheap_ref[9];
   std::copy(array, array + length, popheap);
@@ -81,6 +82,8 @@ check_pop(int* array, int length)
 void
 check_sort(int* array, int length)
 {
+  bool test __attribute__((unused)) = true;
+
   rvalstruct sortheap[9];
   int        sortheap_ref[9];
   std::copy(array, array + length, sortheap);
@@ -99,6 +102,8 @@ check_sort(int* array, int length)
 void
 check_push(int* array, int pushval, int length)
 {
+  bool test __attribute__((unused)) = true;
+
   rvalstruct pushheap[10];
   int        pushheap_ref[10];
   std::copy(array, array + length, pushheap);
diff --git a/libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc b/libstdc++-v3/testsuite/25_algorithms/heap/moveable2.cc
new file mode 100644 (file)
index 0000000..86eefbe
--- /dev/null
@@ -0,0 +1,157 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without Pred 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++0x -DITERATIONS=5" { target simulator } }
+
+// 25.3.6 Heap operations [lib.alg.heap.operations]
+
+#undef _GLIBCXX_CONCEPT_CHECKS
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_rvalref.h>
+
+#ifndef ITERATIONS
+#define ITERATIONS 9
+#endif
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+using __gnu_test::rvalstruct;
+
+typedef test_container<rvalstruct, random_access_iterator_wrapper> container;
+typedef test_container<int, random_access_iterator_wrapper> container_ref;
+
+bool are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
+{ return lhs < rhs; }
+
+bool are_ordered_int(const int& lhs, const int& rhs)
+{ return lhs < rhs; }
+
+void 
+check_make(int* array, int length)
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct makeheap[9];
+  int        makeheap_ref[9];
+  std::copy(array, array + length, makeheap);
+  std::copy(array, array + length, makeheap_ref);  
+  container makecon(makeheap, makeheap + length);
+  container_ref makecon_ref(makeheap_ref, makeheap_ref + length);
+  std::make_heap(makecon.begin(), makecon.end(), are_ordered);
+  std::make_heap(makecon_ref.begin(), makecon_ref.end(), are_ordered_int);
+  for (int z = 0; z < length; ++z)
+    VERIFY( makeheap[z] == makeheap_ref[z] );
+  VERIFY( std::__is_heap(makecon.begin(), makecon.end(), are_ordered) );
+  for (int z = 0; z < length; ++z)
+    VERIFY( makeheap[z].valid );
+}
+
+void
+check_pop(int* array, int length)
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct popheap[9];
+  int        popheap_ref[9];
+  std::copy(array, array + length, popheap);
+  std::copy(array, array + length, popheap_ref);
+  container popcon(popheap, popheap + length);
+  container_ref popcon_ref(popheap_ref, popheap_ref + length);
+  std::pop_heap(popcon.begin(), popcon.end(), are_ordered);
+  std::pop_heap(popcon_ref.begin(), popcon_ref.end(), are_ordered_int);
+  for (int z = 0; z < length; ++z)
+    VERIFY( popheap[z] == popheap_ref[z] );
+  VERIFY( (std::__is_heap(popheap, popheap + length - 1), are_ordered) );
+  for (int z = 0; z < length; ++z)
+    VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid );
+}
+
+void
+check_sort(int* array, int length)
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct sortheap[9];
+  int        sortheap_ref[9];
+  std::copy(array, array + length, sortheap);
+  std::copy(array, array + length, sortheap_ref);
+  container sortcon(sortheap, sortheap + length);
+  container_ref sortcon_ref(sortheap_ref, sortheap_ref + length);
+  std::sort_heap(sortcon.begin(), sortcon.end(), are_ordered);
+  std::sort_heap(sortcon_ref.begin(), sortcon_ref.end(), are_ordered_int);
+  for (int z = 0; z < length; ++z)
+    VERIFY( sortheap[z] == sortheap_ref[z] );
+  for (int z = 0; z < length - 1; ++z)
+    VERIFY( sortheap[z].val <= sortheap[z + 1].val && sortheap[z].valid );
+  VERIFY( sortheap[length - 1].valid );
+}
+
+void
+check_push(int* array, int pushval, int length)
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct pushheap[10];
+  int        pushheap_ref[10];
+  std::copy(array, array + length, pushheap);
+  std::copy(array, array + length, pushheap_ref);  
+  pushheap[length] = pushval;
+  pushheap_ref[length] = pushval;
+  container pushcon(pushheap, pushheap + length + 1);
+  container_ref pushcon_ref(pushheap_ref, pushheap_ref + length + 1);
+  std::push_heap(pushcon.begin(), pushcon.end(), are_ordered);
+  std::push_heap(pushcon_ref.begin(), pushcon_ref.end(), are_ordered_int);
+  for (int z = 0; z < length + 1; ++z)
+    VERIFY( pushheap[z] == pushheap_ref[z] );
+  VERIFY( std::__is_heap(pushheap, pushheap + length + 1) );
+  for (int z = 0; z < length + 1; ++z)
+    VERIFY( pushheap[z].valid );
+}
+
+void
+test01()
+{
+  int array[9];
+  for (int i = 1; i < ITERATIONS; ++i)
+    {
+      for(int z = 0; z < i; ++z)
+       array[z] = z;
+      while (std::next_permutation(array, array + i))
+       {
+         check_make(array, i);
+         if (std::__is_heap(array, array + i, are_ordered_int))
+           {
+             check_pop(array, i);
+             check_sort(array, i);
+             for (int pushval = -1; pushval <= i; ++pushval)
+               check_push(array, pushval, i);
+           }
+       }
+    }
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
index d3195ab..d4da753 100644 (file)
@@ -27,11 +27,10 @@ using std::inplace_merge;
 
 typedef test_container<int, bidirectional_iterator_wrapper> container;
 
-
 void 
 test1()
 {
-  int array[]={1};
+  int array[] = { 1 };
   container con1(array, array);
   inplace_merge(con1.begin(), con1.end(), con1.end());
   container con2(array, array + 1);
@@ -42,11 +41,13 @@ test1()
 void 
 test2()
 {
-  int array[]={0,2,4,1,3,5};
+  bool test __attribute__((unused)) = true;
+
+  int array[] = { 0, 2, 4, 1, 3, 5 };
   container con(array, array + 6);
   inplace_merge(con.begin(), con.it(3), con.end());
-  VERIFY(array[0] == 0 && array[1] == 1 && array[2] == 2 &&
-        array[3] == 3 && array[4] == 4 && array[5] == 5);
+  VERIFY( array[0] == 0 && array[1] == 1 && array[2] == 2
+         && array[3] == 3 && array[4] == 4 && array[5] == 5 );
 }
 
 struct S
@@ -57,12 +58,14 @@ struct S
   S() { }
   bool 
   operator<(const S& _s) const 
-  { return _s.a < a; }
+  { return a < _s.a; }
 };
 
 void 
 test3()
 {
+  bool test __attribute__((unused)) = true;
+
   S s[4];
   s[0].a = 0;
   s[1].a = 1;
@@ -73,11 +76,14 @@ test3()
   s[2].b = 1;
   s[3].b = 1;
   inplace_merge(s, s + 2, s + 4);
-  VERIFY(s[0].b == 0 && s[1].b == 1 && s[2].b == 0 && s[3].b == 1);
+  VERIFY( s[0].b == 0 && s[1].b == 1 && s[2].b == 0 && s[3].b == 1 );
 }
 
 int 
 main()
 {
   test1();
+  test2();
+  test3();
+  return 0;
 }
index 085fbe0..b577cfa 100644 (file)
@@ -18,7 +18,6 @@
 // <http://www.gnu.org/licenses/>.
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define  _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <testsuite_hooks.h>
index 7d46ab3..436ccb0 100644 (file)
@@ -18,7 +18,6 @@
 // <http://www.gnu.org/licenses/>.
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define  _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <testsuite_hooks.h>
diff --git a/libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/next_permutation/moveable.cc
new file mode 100644 (file)
index 0000000..d754f6b
--- /dev/null
@@ -0,0 +1,121 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 25.3.9 [lib.alg.permutation.generators]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_rvalref.h>
+
+using __gnu_test::test_container;
+using __gnu_test::bidirectional_iterator_wrapper;
+using __gnu_test::rvalstruct;
+using std::next_permutation;
+
+typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
+
+void
+test1()
+{
+  bool test __attribute__((unused)) = true;
+
+  // Note: The standard is unclear on what should happen in this case.
+  // This seems the only really sensible behaviour, and what is done.
+  rvalstruct array[] = {0};
+  Container con(array, array);
+  VERIFY( !next_permutation(con.begin(), con.end()) );
+}
+
+void
+test2()
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct array[] = {0};
+  Container con(array, array + 1);
+  VERIFY( !next_permutation(con.begin(), con.end()) );
+}
+
+void
+test3()
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct array[] = {0, 3};
+  Container con(array, array + 2);
+  VERIFY( next_permutation(con.begin(), con.end()) );
+  VERIFY( array[0] == 3 && array[1] == 0 );
+  VERIFY( !next_permutation(con.begin(), con.end()) );
+  VERIFY( array[0] == 0 && array[1] == 3 );
+}
+
+void
+test4()
+{
+  bool test __attribute__((unused)) = true;
+
+  int array[6] = {0, 1, 2, 3, 4, 5};
+  for(int i = 0 ; i < 719; ++i)
+    {
+      rvalstruct temp_array[6];
+      std::copy(array, array + 6, temp_array);
+      Container con(temp_array, temp_array + 6);
+      VERIFY( next_permutation(array, array + 6) );
+      VERIFY( std::lexicographical_compare(temp_array, temp_array + 6, 
+                                          array, array + 6) );
+    }
+  VERIFY( !next_permutation(array,array + 6) );
+  for(int i = 0; i < 6; ++i)
+    VERIFY( array[i] == i );
+}
+
+bool
+are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
+{ return lhs < rhs; }
+
+void
+test5()
+{
+  bool test __attribute__((unused)) = true;
+
+  int array[6] = {0, 1, 2, 3, 4, 5};
+  for(int i = 0 ; i < 719; ++i)
+    {
+      rvalstruct temp_array[6];
+      std::copy(array, array + 6, temp_array);
+      Container con(temp_array, temp_array + 6);
+      VERIFY( next_permutation(array, array + 6, are_ordered) );
+      VERIFY( std::lexicographical_compare(temp_array, temp_array + 6,
+                                          array, array + 6, are_ordered) );
+    }
+  VERIFY( !next_permutation(array,array + 6, are_ordered) );
+  for(int i = 0; i < 6; ++i)
+    VERIFY( array[i] == i );
+}
+
+int main()
+{
+  test1();
+  test2();
+  test3();
+  test4();
+  test5();
+  return 0;
+}
index 005f6ec..93a514f 100644 (file)
@@ -1,6 +1,6 @@
 // { dg-options "-std=gnu++0x" }
 
-// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009 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
@@ -36,33 +36,59 @@ typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
 void 
 test1()
 {
+  bool test __attribute__((unused)) = true;
+
   int intarray[] = {6, 5, 4, 3, 2, 1, 0};
   rvalstruct array[7];
   std::copy(intarray, intarray + 7, array);
   Container con(array, array + 7);
   nth_element(con.begin(), con.it(3), con.end());
   for(int i = 0; i < 3; ++i)
-    VERIFY(array[i].val < 3);
+    VERIFY( array[i].val < 3 );
   for(int i = 4; i < 7; ++i)
-    VERIFY(array[i].val > 3);
+    VERIFY( array[i].val > 3 );
   for(int i = 0; i < 7; ++i)
-    VERIFY(array[i].valid);
+    VERIFY( array[i].valid );
 }
 
 void 
 test2()
 {
+  bool test __attribute__((unused)) = true;
+
   int intarray[] = {0, 6, 1, 5, 2, 4, 3};
   rvalstruct array[7];
   std::copy(intarray, intarray + 7, array);
   Container con(array,array + 7);
   nth_element(con.begin(), con.it(3), con.end());
   for(int i = 0; i < 3; ++i)
-    VERIFY(array[i].val < 3);
+    VERIFY( array[i].val < 3 );
+  for(int i = 4; i < 7; ++i)
+    VERIFY( array[i].val > 3 );
+  for(int i = 0; i < 7; ++i)
+    VERIFY( array[i].valid );  
+}
+
+bool
+are_less(const rvalstruct& lhs, const rvalstruct& rhs)
+{ return lhs < rhs; }
+
+void 
+test3()
+{
+  bool test __attribute__((unused)) = true;
+
+  int intarray[] = {0, 6, 1, 5, 2, 4, 3};
+  rvalstruct array[7];
+  std::copy(intarray, intarray + 7, array);
+  Container con(array,array + 7);
+  nth_element(con.begin(), con.it(3), con.end(), are_less);
+  for(int i = 0; i < 3; ++i)
+    VERIFY( array[i].val < 3 );
   for(int i = 4; i < 7; ++i)
-    VERIFY(array[i].val > 3);
+    VERIFY( array[i].val > 3 );
   for(int i = 0; i < 7; ++i)
-    VERIFY(array[i].valid);  
+    VERIFY( array[i].valid );  
 }
 
 int 
@@ -70,5 +96,6 @@ main()
 {
   test1();
   test2();
+  test3();
   return 0;
 }
index 8328bd5..fcad384 100644 (file)
@@ -1,6 +1,6 @@
 // { dg-options "-std=gnu++0x" }
 
-// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009 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
@@ -20,7 +20,6 @@
 // 25.3.1.3 [lib.partial.sort]
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <testsuite_hooks.h>
@@ -37,27 +36,49 @@ typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
 void 
 test1()
 {
+  bool test __attribute__((unused)) = true;
+
   int intarray[] = {6, 5, 4, 3, 2, 1, 0};
   rvalstruct array[7];
   std::copy(intarray, intarray + 7, array);
   Container con(array, array + 7);
   partial_sort(con.begin(), con.it(3), con.end());
-  VERIFY(array[0].val == 0 && array[1].val == 1 && array[2].val == 2);
+  VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 );
   for(int i = 0; i < 7; ++i)
-    VERIFY(array[i].valid);
+    VERIFY( array[i].valid );
 }
 
 void 
 test2()
 {
+  bool test __attribute__((unused)) = true;
+
   int intarray[] = {0, 6, 1, 5, 2, 4, 3};
   rvalstruct array[7];
   std::copy(intarray, intarray + 7, array);
   Container con(array,array + 7);
   partial_sort(con.begin(), con.it(3), con.end());
-  VERIFY(array[0].val == 0 && array[1].val == 1 && array[2].val == 2);
+  VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 );
+  for(int i = 0; i < 7; ++i)
+    VERIFY( array[i].valid );
+}
+
+bool are_less(const rvalstruct& lhs, const rvalstruct& rhs)
+{ return lhs < rhs; }
+
+void 
+test3()
+{
+  bool test __attribute__((unused)) = true;
+
+  int intarray[] = {0, 6, 1, 5, 2, 4, 3};
+  rvalstruct array[7];
+  std::copy(intarray, intarray + 7, array);
+  Container con(array,array + 7);
+  partial_sort(con.begin(), con.it(3), con.end(), are_less);
+  VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 );
   for(int i = 0; i < 7; ++i)
-    VERIFY(array[i].valid);
+    VERIFY( array[i].valid );
 }
 
 int 
@@ -65,4 +86,6 @@ main()
 {
   test1();
   test2();
+  test3();
+  return 0;
 }
diff --git a/libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc
new file mode 100644 (file)
index 0000000..796c5df
--- /dev/null
@@ -0,0 +1,121 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 25.3.9 [lib.alg.permutation.generators]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_rvalref.h>
+
+using __gnu_test::test_container;
+using __gnu_test::bidirectional_iterator_wrapper;
+using __gnu_test::rvalstruct;
+using std::prev_permutation;
+
+typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
+
+void
+test1()
+{
+  bool test __attribute__((unused)) = true;
+
+  // Note: The standard is unclear on what should happen in this case.
+  // This seems the only really sensible behaviour, and what is done.
+  rvalstruct array[] = {0};
+  Container con(array, array);
+  VERIFY( !prev_permutation(con.begin(), con.end()) );
+}
+
+void
+test2()
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct array[] = {0};
+  Container con(array, array + 1);
+  VERIFY( !prev_permutation(con.begin(), con.end()) );
+}
+
+void
+test3()
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct array[] = {3, 0};
+  Container con(array, array + 2);
+  VERIFY( prev_permutation(con.begin(), con.end()) );
+  VERIFY( array[0] == 0 && array[1] == 3 );
+  VERIFY( !prev_permutation(con.begin(), con.end()) );
+  VERIFY( array[0] == 3 && array[1] == 0 );
+}
+
+void
+test4()
+{
+  bool test __attribute__((unused)) = true;
+
+  int array[6] = {5, 4, 3, 2, 1, 0};
+  for(int i = 0 ; i < 719; ++i)
+    {
+      rvalstruct temp_array[6];
+      std::copy(array, array + 6, temp_array);
+      Container con(temp_array, temp_array + 6);
+      VERIFY( prev_permutation(array, array + 6) );
+      VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6, 
+                                           array, array + 6) );
+    }
+  VERIFY( !prev_permutation(array,array + 6)) ;
+  for(int i = 0; i < 6; ++i)
+    VERIFY( array[i] == (5 - i) );
+}
+
+bool
+are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
+{ return lhs < rhs; }
+
+void
+test5()
+{
+  bool test __attribute__((unused)) = true;
+
+  int array[6] = {5, 4, 3, 2, 1, 0};
+  for(int i = 0 ; i < 719; ++i)
+    {
+      rvalstruct temp_array[6];
+      std::copy(array, array + 6, temp_array);
+      Container con(temp_array, temp_array + 6);
+      VERIFY( prev_permutation(array, array + 6, are_ordered) );
+      VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6, 
+                                           array, array + 6, are_ordered) );
+    }
+  VERIFY( !prev_permutation(array,array + 6, are_ordered) );
+  for(int i = 0; i < 6; ++i)
+    VERIFY( array[i] == (5 - i) );
+}
+
+int main()
+{
+  test1();
+  test2();
+  test3();
+  test4();
+  test5();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc b/libstdc++-v3/testsuite/25_algorithms/random_shuffle/moveable.cc
new file mode 100644 (file)
index 0000000..6a44bb8
--- /dev/null
@@ -0,0 +1,85 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 25.2.11 random_shuffle()
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+#include <testsuite_rvalref.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+using __gnu_test::rvalstruct;
+
+typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
+
+const int N = 200000;
+int A[N];
+
+void fill_ascending()
+{
+  for (int i = 0; i < N; ++i)
+    A[i] = i;
+}
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  fill_ascending();
+  rvalstruct rv[N];
+  std::copy(A, A + N, rv);
+  Container con(rv, rv + N);
+  std::random_shuffle(con.begin(), con.end());
+
+  // The chance that random_shuffle leaves the order as is by coincidence
+  // is negligible, so we expect it to be permuted
+  VERIFY( !std::equal(rv, rv + N, A) );
+
+  std::sort(con.begin(), con.end());
+  VERIFY( std::equal(rv, rv + N, A) );
+}
+
+int random_generator(int)
+{ return 0; }
+
+void
+test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  fill_ascending();
+  rvalstruct rv[10] = {1,2,3,4,5,6,7,8,9,10};
+  int result[10] = {10,1,2,3,4,5,6,7,8,9};
+  Container con(rv, rv + 10);
+  std::random_shuffle(con.begin(), con.end(), random_generator);
+  // The above answer was generated by hand. It is not required by the standard,
+  // but is produced by the current algorithm.
+  VERIFY( std::equal(rv, rv + 10, result) );
+}
+
+int
+main()
+{
+  test01();
+  test02();
+  return 0;
+}
index 61f4473..6972d16 100644 (file)
@@ -1,7 +1,6 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
-// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009 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
 // 25.3.1 algorithms, sort()
 
 #undef _GLIBCXX_CONCEPT_CHECKS
-#define _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
 
 #include <algorithm>
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
 #include <testsuite_rvalref.h>
 
-bool test __attribute__((unused)) = true;
-
 using __gnu_test::test_container;
 using __gnu_test::random_access_iterator_wrapper;
 using __gnu_test::rvalstruct;
@@ -37,27 +33,47 @@ using std::partial_sort;
 
 typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
 
-
 const int A[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 
-                       17, 8, 18, 9, 19};
+                17, 8, 18, 9, 19};
 const int N = sizeof(A) / sizeof(int);
 
 // 25.3.1.1 sort()
 void
 test01()
 {
-    rvalstruct s1[N];
-    std::copy(A, A + N, s1);
-    Container con(s1, s1 + N);
-    std::sort(con.begin(), con.end());
-    VERIFY(s1[0].valid);
-    for(int i = 1; i < N; ++i)
-      VERIFY(s1[i].val>s1[i-1].val && s1[i].valid);
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct s1[N];
+  std::copy(A, A + N, s1);
+  Container con(s1, s1 + N);
+  std::sort(con.begin(), con.end());
+  VERIFY( s1[0].valid );
+  for(int i = 1; i < N; ++i)
+    VERIFY( s1[i].val>s1[i-1].val && s1[i].valid );
+}
+
+bool order(const rvalstruct& lhs, const rvalstruct& rhs)
+{ return lhs < rhs; }
+
+// 25.3.1.1 sort()
+void
+test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  rvalstruct s1[N];
+  std::copy(A, A + N, s1);
+  Container con(s1, s1 + N);
+  std::sort(con.begin(), con.end(), order);
+  VERIFY( s1[0].valid );
+  for(int i = 1; i < N; ++i)
+    VERIFY( s1[i].val>s1[i-1].val && s1[i].valid );
 }
 
 int
 main()
 {
   test01();
+  test02();
   return 0;
 }
index 6f072d5..b5bf16d 100644 (file)
@@ -1,6 +1,6 @@
 // { dg-options "-std=gnu++0x" }
 
-// Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009 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
@@ -54,19 +54,52 @@ void test01()
 
   Container con(T1, T1 + N);
 
-  VERIFY(std::unique(con.begin(), con.end()).ptr - T1 == 12);
+  VERIFY( std::unique(con.begin(), con.end()).ptr - T1 == 12 );
   for(int i = 0; i < 12; ++i)
-    VERIFY(T1[i].val == A1[i]);
+    VERIFY( T1[i].val == A1[i] );
 
   Container con2(T2, T2 + N);
-  VERIFY(std::unique(con2.begin(), con2.end()).ptr - T2 == 8);
+  VERIFY( std::unique(con2.begin(), con2.end()).ptr - T2 == 8 );
   for(int i = 0; i < 8; ++i)
-    VERIFY(T2[i].val == B1[i]);
+    VERIFY( T2[i].val == B1[i] );
 }
 
+bool are_equal(const rvalstruct& rhs, const rvalstruct& lhs)
+{ return rhs == lhs; }
+
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4};
+  int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9};
+
+  const int N = sizeof(intarray1) / sizeof(int);
+
+  rvalstruct T1[N];
+  rvalstruct T2[N];
+  
+  std::copy(intarray1,intarray1 + N, T1);
+  std::copy(intarray2,intarray2 + N, T2);
+  
+  const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4};
+  const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9};
+
+  Container con(T1, T1 + N);
+
+  VERIFY( std::unique(con.begin(), con.end(), are_equal).ptr - T1 == 12 );
+  for(int i = 0; i < 12; ++i)
+    VERIFY( T1[i].val == A1[i] );
+
+  Container con2(T2, T2 + N);
+  VERIFY( std::unique(con2.begin(), con2.end(), are_equal).ptr - T2 == 8 );
+  for(int i = 0; i < 8; ++i)
+    VERIFY( T2[i].val == B1[i] );
+}
 
 int main()
 {
   test01();
+  test02();
   return 0;
 }
index 1b14c89..14a725f 100644 (file)
@@ -88,23 +88,23 @@ namespace __gnu_test
        ptr(ptr_in), SharedInfo(SharedInfo_in)
       { }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
       template<class U>
       void
-      operator=(const U& new_val)
+      operator=(U&& new_val)
       {
        ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0);
        SharedInfo->writtento[ptr - SharedInfo->first] = 1;
-       *ptr = new_val;
+       *ptr = std::forward<U>(new_val);
       }
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#else
       template<class U>
       void
-      operator=(U&& new_val)
+      operator=(const U& new_val)
       {
        ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0);
        SharedInfo->writtento[ptr - SharedInfo->first] = 1;
-       *ptr = std::move(new_val);
+       *ptr = new_val;
       }
 #endif
     };
index 4e2f59c..b44d6dd 100644 (file)
@@ -35,19 +35,9 @@ namespace __gnu_test
     bool
     operator=(const rvalstruct&);
 
-// Normally we don't define a copy constructor, as any use of it would
-// show an inefficency. In some cases we know it will be aliased away
-// by the compiler, but it still insists it is defined, so we provide
-// a way of making it public but not giving a body, so any usage would
-// instead fail at link-time.
-#ifdef _GLIBCXX_TESTSUITE_ALLOW_RVALREF_ALIASING
-  public:
-    rvalstruct(const rvalstruct&);
-#else
     rvalstruct(const rvalstruct&);
 
   public:
-#endif
     int val;
     bool valid;