Commit 5348e86a authored by bkoz's avatar bkoz
Browse files

2007-10-03 Chris Jefferson <chris@bubblescope.net>

	    Benjamin Kosnik  <bkoz@redhat.com>

	* testsuite/20_util/pair/moveable.cc: New. Merge from 
	libstdcxx_so_7-branch.
	* testsuite/23_containers/deque/capacity/moveable.cc: Same.
	* testsuite/23_containers/deque/cons/moveable.cc: Same.
	* testsuite/23_containers/deque/modifiers/moveable.cc: Same.
	* testsuite/23_containers/deque/moveable.cc: Same.
	* testsuite/23_containers/list/moveable.cc: Same.
	* testsuite/23_containers/map/moveable.cc: Same.
	* testsuite/23_containers/multimap/moveable.cc: Same.
	* testsuite/23_containers/multiset/moveable.cc: Same.
	* testsuite/23_containers/set/moveable.cc: Same.
	* testsuite/23_containers/vector/cons/moveable.cc: Same.
	* testsuite/23_containers/vector/modifiers/moveable.cc: Same.
	* testsuite/23_containers/vector/moveable.cc: Same.
	* testsuite/23_containers/vector/resize/moveable.cc: Same.
	* testsuite/25_algorithms/heap/moveable.cc: Same.
	* testsuite/25_algorithms/nth_element/moveable.cc: Same.
	* testsuite/25_algorithms/partial_sort/moveable.cc: Same.
	* testsuite/25_algorithms/partition/moveable.cc: Same.
	* testsuite/25_algorithms/remove_if/moveable.cc: Same.
	* testsuite/25_algorithms/remove/moveable.cc: Same.
	* testsuite/25_algorithms/reverse/moveable.cc: Same.
	* testsuite/25_algorithms/rotate/moveable.cc: Same.
	* testsuite/25_algorithms/sort/moveable.cc: Same.
	* testsuite/25_algorithms/swap_ranges/moveable.cc: Same.
	* testsuite/25_algorithms/unique/moveable.cc: Same.
	* testsuite/util/testsuite_rvalref.h: New.

	* testsuite/25_algorithms/equal/equal.cc: Move to...
	* testsuite/25_algorithms/equal/no_operator_ne.cc: ...this.
	* testsuite/25_algorithms/heap/heap.cc: Move to...
	* testsuite/25_algorithms/heap/1.cc: ...this.
	* testsuite/25_algorithms/lower_bound/lower_bound.cc: Move to...
	* testsuite/25_algorithms/lower_bound/no_operator_ne.cc: ...this.
	* testsuite/25_algorithms/partition/partition.cc: Move to...
	* testsuite/25_algorithms/partition/1.cc: ...this.
	* testsuite/25_algorithms/stable_partition/1.cc: ... and this.
	
	* testsuite/25_algorithms/search/1.cc: Update from merge.
	* testsuite/25_algorithms/search/check_type.cc: Same.

	* testsuite/lib/dg-options.exp (dg-require-rvalref): New.
	* testsuite/lib/libstdc++.exp (check_v3_target_rvalref): New.
	


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128990 138bc75d-0d04-0410-961f-82ee72b054a4
parent 9c78c8fe
2007-10-03 Chris Jefferson <chris@bubblescope.net>
Benjamin Kosnik <bkoz@redhat.com>
* testsuite/20_util/pair/moveable.cc: New. Merge from
libstdcxx_so_7-branch.
* testsuite/23_containers/deque/capacity/moveable.cc: Same.
* testsuite/23_containers/deque/cons/moveable.cc: Same.
* testsuite/23_containers/deque/modifiers/moveable.cc: Same.
* testsuite/23_containers/deque/moveable.cc: Same.
* testsuite/23_containers/list/moveable.cc: Same.
* testsuite/23_containers/map/moveable.cc: Same.
* testsuite/23_containers/multimap/moveable.cc: Same.
* testsuite/23_containers/multiset/moveable.cc: Same.
* testsuite/23_containers/set/moveable.cc: Same.
* testsuite/23_containers/vector/cons/moveable.cc: Same.
* testsuite/23_containers/vector/modifiers/moveable.cc: Same.
* testsuite/23_containers/vector/moveable.cc: Same.
* testsuite/23_containers/vector/resize/moveable.cc: Same.
* testsuite/25_algorithms/heap/moveable.cc: Same.
* testsuite/25_algorithms/nth_element/moveable.cc: Same.
* testsuite/25_algorithms/partial_sort/moveable.cc: Same.
* testsuite/25_algorithms/partition/moveable.cc: Same.
* testsuite/25_algorithms/remove_if/moveable.cc: Same.
* testsuite/25_algorithms/remove/moveable.cc: Same.
* testsuite/25_algorithms/reverse/moveable.cc: Same.
* testsuite/25_algorithms/rotate/moveable.cc: Same.
* testsuite/25_algorithms/sort/moveable.cc: Same.
* testsuite/25_algorithms/swap_ranges/moveable.cc: Same.
* testsuite/25_algorithms/unique/moveable.cc: Same.
* testsuite/util/testsuite_rvalref.h: New.
* testsuite/25_algorithms/equal/equal.cc: Move to...
* testsuite/25_algorithms/equal/no_operator_ne.cc: ...this.
* testsuite/25_algorithms/heap/heap.cc: Move to...
* testsuite/25_algorithms/heap/1.cc: ...this.
* testsuite/25_algorithms/lower_bound/lower_bound.cc: Move to...
* testsuite/25_algorithms/lower_bound/no_operator_ne.cc: ...this.
* testsuite/25_algorithms/partition/partition.cc: Move to...
* testsuite/25_algorithms/partition/1.cc: ...this.
* testsuite/25_algorithms/stable_partition/1.cc: ... and this.
* testsuite/25_algorithms/search/1.cc: Update from merge.
* testsuite/25_algorithms/search/check_type.cc: Same.
* testsuite/lib/dg-options.exp (dg-require-rvalref): New.
* testsuite/lib/libstdc++.exp (check_v3_target_rvalref): New.
2007-10-03 Richard Sandiford <richard@codesourcery.com>
* acinclude.m4 (GLIBCXX_ENABLE_C99): Temporarily add
......@@ -46,8 +93,13 @@
* testsuite/25_algorithms/upper_bound/2.cc: ... this.
* testsuite/25_algorithms/lower_bound/2.cc: ... this.
* testsuite/25_algorithms/equal_range/2.cc: ... and this.
* testsuite/25_algorithms/sort/vectorbool.cc: Add from
2007-10-02 Chris Jefferson <chris@bubblescope.net>
* testsuite/25_algorithms/search/1.cc: Merge from
libstdcxx_so_7-branch.
* testsuite/25_algorithms/search/check_type.cc: Same.
* testsuite/25_algorithms/sort/vectorbool.cc: Same.
2007-09-30 Jonathan Wakely <jwakely.gcc@gmail.com>
......
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on pair, and also vector. If the implementation
// changes this test may begin to fail.
#include <vector>
#include <utility>
#include <testsuite_hooks.h>
bool test __attribute__((unused)) = true;
void
test1()
{
std::pair<int,int> a(1,1),b(2,2);
a=std::move(b);
VERIFY(a.first == 2 && a.second == 2 && b.first == 2 && b.second == 2);
std::pair<int,int> c(std::move(a));
VERIFY(c.first == 2 && c.second == 2 && a.first == 2 && a.second == 2);
}
void
test2()
{
std::vector<int> v,w;
v.push_back(1);
w.push_back(2);
w.push_back(2);
std::pair<int, std::vector<int> > p = make_pair(1,v);
std::pair<int, std::vector<int> > q = make_pair(2,w);
p = std::move(q);
VERIFY(p.first == 2 && q.first == 2 &&
p.second.size() == 2 && q.second.size() == 1);
std::pair<int, std::vector<int> > r(std::move(p));
VERIFY(r.first == 2 && p.first == 2 &&
r.second.size() == 2 && p.second.size() == 0);
}
int
main()
{
test1();
test2();
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2006, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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 <deque>
#include <testsuite_hooks.h>
#include <testsuite_rvalref.h>
using namespace __gnu_test;
// According to n1771, there should be two resizes, with and without
// parameter. We only have one at present, whose second parameter defaults
// to a default-constructed object.
void
test01()
{
bool test __attribute__((unused)) = true;
std::deque<copycounter> a;
copycounter::copycount = 0;
a.resize(10);
a.resize(98);
a.resize(99);
a.resize(100);
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 100 );
#else
VERIFY( copycounter::copycount == 100 + 4 );
#endif
a.resize(99);
a.resize(0);
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 100 );
#else
VERIFY( copycounter::copycount == 100 + 6 );
#endif
a.resize(100);
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 200 );
#else
VERIFY( copycounter::copycount == 200 + 7 );
#endif
a.clear();
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 200 );
#else
VERIFY( copycounter::copycount == 200 + 7 );
#endif
}
int main()
{
test01();
return 0;
}
// { dg-do compile }
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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 <deque>
#include <iterator>
#include <testsuite_iterators.h>
#include <testsuite_rvalref.h>
using namespace __gnu_test;
typedef std::deque<rvalstruct> test_type;
// Empty constructor doesn't require a copy constructor
void
test01()
{ test_type d; }
// Constructing from a range that returns rvalue references doesn't
// require a copy constructor.
void
test02(rvalstruct* begin, rvalstruct* end)
{
test_type d(std::make_move_iterator(begin), std::make_move_iterator(end));
}
// Constructing from a input iterator range that returns rvalue
// references doesn't require a copy constructor either.
void
test03(input_iterator_wrapper<rvalstruct> begin,
input_iterator_wrapper<rvalstruct> end)
{
test_type d(std::make_move_iterator(begin), std::make_move_iterator(end));
}
// Neither does destroying one.
void
test04(test_type* d)
{ delete d; }
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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 <deque>
#include <testsuite_hooks.h>
#include <testsuite_rvalref.h>
using namespace __gnu_test;
// Test deque::push_back makes no unneeded copies.
void
test01()
{
bool test __attribute__((unused)) = true;
std::deque<copycounter> a;
copycounter c(1);
copycounter::copycount = 0;
for(int i = 0; i < 1000; ++i)
a.push_back(c);
VERIFY(copycounter::copycount == 1000);
}
// Test deque::push_front makes no unneeded copies.
void
test02()
{
bool test __attribute__((unused)) = true;
std::deque<copycounter> a;
copycounter c(1);
copycounter::copycount = 0;
for(int i = 0; i < 1000; ++i)
a.push_front(c);
VERIFY(copycounter::copycount == 1000);
}
// Test deque::insert makes no unneeded copies.
void
test03()
{
bool test __attribute__((unused)) = true;
std::deque<copycounter> a(1000);
copycounter c(1);
copycounter::copycount = 0;
a.insert(a.begin(),c);
a.insert(a.end(),c);
for(int i = 0; i < 500; ++i)
a.insert(a.begin() + i, c);
VERIFY(copycounter::copycount == 502);
}
// Test deque::insert(iterator, count, value) makes no unneeded copies
// when it has to also reallocate the deque's internal buffer.
void
test04()
{
bool test __attribute__((unused)) = true;
copycounter c(1);
std::deque<copycounter> a(10, c);
copycounter::copycount = 0;
a.insert(a.begin(), 20, c);
VERIFY(copycounter::copycount == 20);
a.insert(a.end(), 50, c);
VERIFY(copycounter::copycount == 70);
// NOTE : These values are each one higher than might be expected, as
// deque::insert(iterator, count, value) copies the value it is given
// when it has to move elements in the deque in case that value is
// in the deque.
// Near the start
a.insert(a.begin() + 10, 100, c);
VERIFY(copycounter::copycount == 170 + 1);
// Near the end
a.insert(a.end() - 10, 1000, c);
VERIFY(copycounter::copycount == 1170 + 2);
}
// Test deque::insert(iterator, count, value) makes no unneeded copies
// when it doesn't have to reallocate the deque's internal buffer.
void
test05()
{
bool test __attribute__((unused)) = true;
copycounter c(1);
std::deque<copycounter> a(10, c);
copycounter::copycount = 0;
//a.reserve(1000);
a.insert(a.begin(), 20, c);
VERIFY(copycounter::copycount == 20 );
a.insert(a.end(), 50, c);
VERIFY(copycounter::copycount == 70 );
// NOTE : These values are each one higher than might be expected, as
// deque::insert(iterator, count, value) copies the value it is given
// when it has to move elements in the deque in case that value is
// in the deque.
// Near the start
a.insert(a.begin() + 10, 100, c);
VERIFY(copycounter::copycount == 170 + 1);
// Near the end
a.insert(a.end() - 10, 200, c);
VERIFY(copycounter::copycount == 370 + 2);
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on deque (via swap). If the implementation changed
// this test may begin to fail.
#include <deque>
#include <utility>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
std::deque<int> a,b;
a.push_back(1);
b = std::move(a);
VERIFY( b.size() == 1 && b[0] == 1 && a.size() == 0 );
std::deque<int> c(std::move(b));
VERIFY( c.size() == 1 && c[0] == 1 );
VERIFY( b.size() == 0 );
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on list (via swap). If the implementation changed
// this test may begin to fail.
#include <list>
#include <utility>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
std::list<int> a,b;
a.push_back(1);
b = std::move(a);
VERIFY( b.size() == 1 && *b.begin() == 1 && a.size() == 0 );
std::list<int> c(std::move(b));
VERIFY( c.size() == 1 && *c.begin() == 1 );
VERIFY( b.size() == 0 );
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on map (via swap). If the implementation changed
// this test may begin to fail.
#include <map>
#include <utility>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
std::map<int, int> a,b;
a[2]=0;
b[1]=0;
b = std::move(a);
VERIFY(b.find(2) != b.end() && a.find(1) != a.end());
std::map<int, int> c(std::move(b));
VERIFY( c.find(2) != c.end());
VERIFY( b.find(2) == b.end());
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on multimap (via swap). If the implementation changed
// this test may begin to fail.
#include <map>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
std::multimap<int, int> a,b;
a.insert(std::make_pair(2,0));
b.insert(std::make_pair(1,0));
b = std::move(a);
VERIFY(b.find(2) != b.end() && a.find(1) != a.end());
std::multimap<int, int> c(std::move(b));
VERIFY( c.find(2) != c.end());
VERIFY( b.find(2) == b.end());
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on multiset (via swap). If the implementation changed
// this test may begin to fail.
#include <set>
#include <utility>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
std::multiset<int> a,b;
a.insert(2);
b.insert(1);
b = std::move(a);
VERIFY(b.find(2) != b.end() && a.find(1) != a.end());
std::multiset<int> c(std::move(b));
VERIFY( c.find(2) != c.end());
VERIFY( b.find(2) == b.end());
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on set (via swap). If the implementation changed
// this test may begin to fail.
#include <set>
#include <utility>
#include <testsuite_hooks.h>
int main()
{
bool test __attribute__((unused)) = true;
std::set<int> a,b;
a.insert(2);
b.insert(1);
b = std::move(a);
VERIFY(b.find(2) != b.end() && a.find(1) != a.end());
std::set<int> c(std::move(b));
VERIFY( c.find(2) != c.end());
VERIFY( b.find(2) == b.end());
return 0;
}
// { dg-do compile }
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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 <vector>
#include <iterator>
#include <testsuite_iterators.h>
#include <testsuite_rvalref.h>
using namespace __gnu_test;
typedef std::vector<rvalstruct> test_type;
// Empty constructor doesn't require a copy constructor
void
test01()
{ test_type d; }
// Constructing from a range that returns rvalue references doesn't
// require a copy constructor.
void
test02(rvalstruct* begin, rvalstruct* end)
{
test_type d(std::make_move_iterator(begin), std::make_move_iterator(end));
}
// Constructing from a input iterator range that returns rvalue
// references doesn't require a copy constructor either.
void
test03(input_iterator_wrapper<rvalstruct> begin,
input_iterator_wrapper<rvalstruct> end)
{
test_type d(std::make_move_iterator(begin), std::make_move_iterator(end));
}
// Neither does destroying one.
void
test04(test_type* d)
{ delete d; }
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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 <vector>
#include <testsuite_hooks.h>
#include <testsuite_rvalref.h>
using namespace __gnu_test;
// Test vector::push_back makes no unneeded copies.
void
test01()
{
bool test __attribute__((unused)) = true;
std::vector<copycounter> a;
copycounter c(1);
copycounter::copycount = 0;
for(int i = 0; i < 10; ++i)
a.push_back(c);
VERIFY(copycounter::copycount == 10);
for(int i = 0; i < 100; ++i)
a.insert(a.begin() + i, c);
VERIFY(copycounter::copycount == 110);
for(int i = 0; i < 1000; ++i)
a.insert(a.end(), c);
VERIFY(copycounter::copycount == 1110);
}
// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies
// when it has to also reallocate the vector's internal buffer.
void
test02()
{
bool test __attribute__((unused)) = true;
copycounter c(1);
std::vector<copycounter> a(10, c), b(100, c);
copycounter::copycount = 0;
a.insert(a.begin(), b.begin(), b.begin() + 20);
VERIFY(copycounter::copycount == 20);
a.insert(a.end(), b.begin(), b.begin() + 50);
VERIFY(copycounter::copycount == 70);
a.insert(a.begin() + 50, b.begin(), b.end());
VERIFY(copycounter::copycount == 170);
}
// Test vector::insert(iterator, iterator, iterator) makes no unneeded copies
// when it doesn't have to reallocate the vector's internal buffer.
void
test03()
{
bool test __attribute__((unused)) = true;
copycounter c(1);
std::vector<copycounter> a(10, c), b(100, c);
copycounter::copycount = 0;
a.reserve(1000);
VERIFY(copycounter::copycount == 0);
a.insert(a.begin(), b.begin(), b.begin() + 20);
VERIFY(copycounter::copycount == 20);
a.insert(a.end(), b.begin(), b.begin() + 50);
VERIFY(copycounter::copycount == 70);
a.insert(a.begin() + 50, b.begin(), b.end());
VERIFY(copycounter::copycount == 170);
}
// Test vector::insert(iterator, count, value) makes no unneeded copies
// when it has to also reallocate the vector's internal buffer.
void
test04()
{
bool test __attribute__((unused)) = true;
copycounter c(1);
std::vector<copycounter> a(10, c);
copycounter::copycount = 0;
a.insert(a.begin(), 20, c);
VERIFY(copycounter::copycount == 20 + 1);
a.insert(a.end(), 50, c);
VERIFY(copycounter::copycount == 70 + 2);
a.insert(a.begin() + 50, 100, c);
VERIFY(copycounter::copycount == 170 + 3);
}
// Test vector::insert(iterator, count, value) makes no unneeded copies
// when it doesn't have to reallocate the vector's internal buffer.
void
test05()
{
bool test __attribute__((unused)) = true;
copycounter c(1);
std::vector<copycounter> a(10, c);
copycounter::copycount = 0;
a.reserve(1000);
a.insert(a.begin(), 20, c);
// NOTE : These values are each one higher than might be expected, as
// vector::insert(iterator, count, value) copies the value it is given
// when it doesn't reallocate the buffer.
VERIFY(copycounter::copycount == 20 + 1);
a.insert(a.end(), 50, c);
VERIFY(copycounter::copycount == 70 + 2);
a.insert(a.begin() + 50, 100, c);
VERIFY(copycounter::copycount == 170 + 3);
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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.
// NOTE: This makes use of the fact that we know how moveable
// is implemented on vector (via swap). If the implementation changed
// this test may begin to fail.
#include <vector>
#include <utility>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::vector<int> a,b;
a.push_back(1);
b = std::move(a);
VERIFY( b.size() == 1 && b[0] == 1 && a.size() == 0 );
std::vector<int> c(std::move(b));
VERIFY( c.size() == 1 && c[0] == 1 );
VERIFY( b.size() == 0 );
}
void test02()
{
bool test __attribute__((unused)) = true;
std::vector<bool> a,b;
a.push_back(1);
b = std::move(a);
VERIFY( b.size() == 1 && b[0] == 1 && a.size() == 0 );
std::vector<bool> c(std::move(b));
VERIFY( c.size() == 1 && c[0] == 1 );
VERIFY( b.size() == 0 );
}
int main(void)
{
test01();
test02();
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2006, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// 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 <vector>
#include <testsuite_hooks.h>
#include <testsuite_rvalref.h>
using namespace __gnu_test;
// According to n1771, there should be two resizes, with and without
// parameter. We only have one at present, whose second parameter defaults
// to a default-constructed object.
// Also, the values are one higher than might be expected because internally
// resize calls fill, which copies its input value in case it is already in
// the vector when the vector isn't moved.
void
test01()
{
bool test __attribute__((unused)) = true;
std::vector<copycounter> a;
copycounter::copycount = 0;
a.resize(10);
a.resize(98);
a.resize(99);
a.resize(100);
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 100 + 4 );
#else
VERIFY( copycounter::copycount == 100 + 4 + 4 );
#endif
a.resize(99);
a.resize(0);
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 100 + 4 );
#else
VERIFY( copycounter::copycount == 100 + 4 + 6 );
#endif
a.resize(100);
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 200 + 5 );
#else
VERIFY( copycounter::copycount == 200 + 5 + 7 );
#endif
a.clear();
#ifndef _GLIBCXX_DEBUG
VERIFY( copycounter::copycount == 200 + 5 );
#else
VERIFY( copycounter::copycount == 200 + 5 + 7 );
#endif
}
int main()
{
test01();
return 0;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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 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 COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 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>
#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;
bool test __attribute__((unused)) = true;
void
check_make(int* array, int length)
{
rvalstruct makeheap[9];
std::copy(array, array + length, makeheap);
container makecon(makeheap, makeheap + length);
std::make_heap(makecon.begin(), makecon.end());
VERIFY(std::__is_heap(makecon.begin(), makecon.end()));
for(int z = 0; z < length; ++z)
VERIFY(makeheap[z].valid);
}
void
check_pop(int* array, int length)
{
rvalstruct popheap[9];
std::copy(array, array + length, popheap);
container popcon(popheap, popheap + length);
std::pop_heap(popcon.begin(), popcon.end());
VERIFY(std::__is_heap(popheap, popheap + length - 1));
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)
{
rvalstruct sortheap[9];
std::copy(array, array + length, sortheap);
container sortcon(sortheap, sortheap + length);
std::sort_heap(sortcon.begin(), sortcon.end());
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)
{
rvalstruct pushheap[10];
std::copy(array, array + length, pushheap);
pushheap[length] = pushval;
container pushcon(pushheap, pushheap + length);
std::push_heap(pushcon.begin(), pushcon.end());
VERIFY(std::__is_heap(pushheap, pushheap + length));
for(int z = 0; z < length ; ++z)
VERIFY(pushheap[z].valid);
}
void
test01()
{
int array[9];
for(int i = 1; i < 9; ++i)
{
for(int z = 0; z < i; ++z)
array[i] = i;
while(std::next_permutation(array, array + i))
{
check_make(array, i);
if(std::__is_heap(array, array + i))
{
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;
}
// { dg-require-rvalref "" }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2005, 2007 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// 25.3.2 [lib.alg.nth.element]
#undef _GLIBCXX_CONCEPT_CHECKS
#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 std::nth_element;
using __gnu_test::rvalstruct;
typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
void
test1()
{
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);
for(int i = 4; i < 7; ++i)
VERIFY(array[i].val > 3);
for(int i = 0; i < 7; ++i)
VERIFY(array[i].valid);
}
void
test2()
{
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);
for(int i = 4; i < 7; ++i)
VERIFY(array[i].val > 3);
for(int i = 0; i < 7; ++i)
VERIFY(array[i].valid);
}
int
main()
{
test1();
test2();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment