moveable.cc: New.
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. Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com> From-SVN: r128990
This commit is contained in:
parent
53f8671f97
commit
f5783e34f9
@ -1,3 +1,50 @@
|
||||
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>
|
||||
|
||||
|
73
libstdc++-v3/testsuite/20_util/pair/moveable.cc
Normal file
73
libstdc++-v3/testsuite/20_util/pair/moveable.cc
Normal file
@ -0,0 +1,73 @@
|
||||
// { 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();
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
// { 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;
|
||||
}
|
65
libstdc++-v3/testsuite/23_containers/deque/cons/moveable.cc
Normal file
65
libstdc++-v3/testsuite/23_containers/deque/cons/moveable.cc
Normal file
@ -0,0 +1,65 @@
|
||||
// { 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; }
|
144
libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc
Normal file
144
libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc
Normal file
@ -0,0 +1,144 @@
|
||||
// { 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;
|
||||
}
|
52
libstdc++-v3/testsuite/23_containers/deque/moveable.cc
Normal file
52
libstdc++-v3/testsuite/23_containers/deque/moveable.cc
Normal file
@ -0,0 +1,52 @@
|
||||
// { 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;
|
||||
}
|
52
libstdc++-v3/testsuite/23_containers/list/moveable.cc
Normal file
52
libstdc++-v3/testsuite/23_containers/list/moveable.cc
Normal file
@ -0,0 +1,52 @@
|
||||
// { 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;
|
||||
}
|
53
libstdc++-v3/testsuite/23_containers/map/moveable.cc
Normal file
53
libstdc++-v3/testsuite/23_containers/map/moveable.cc
Normal file
@ -0,0 +1,53 @@
|
||||
// { 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;
|
||||
}
|
52
libstdc++-v3/testsuite/23_containers/multimap/moveable.cc
Normal file
52
libstdc++-v3/testsuite/23_containers/multimap/moveable.cc
Normal file
@ -0,0 +1,52 @@
|
||||
// { 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;
|
||||
}
|
53
libstdc++-v3/testsuite/23_containers/multiset/moveable.cc
Normal file
53
libstdc++-v3/testsuite/23_containers/multiset/moveable.cc
Normal file
@ -0,0 +1,53 @@
|
||||
// { 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;
|
||||
}
|
53
libstdc++-v3/testsuite/23_containers/set/moveable.cc
Normal file
53
libstdc++-v3/testsuite/23_containers/set/moveable.cc
Normal file
@ -0,0 +1,53 @@
|
||||
// { 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;
|
||||
}
|
65
libstdc++-v3/testsuite/23_containers/vector/cons/moveable.cc
Normal file
65
libstdc++-v3/testsuite/23_containers/vector/cons/moveable.cc
Normal file
@ -0,0 +1,65 @@
|
||||
// { 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; }
|
@ -0,0 +1,147 @@
|
||||
// { 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;
|
||||
}
|
72
libstdc++-v3/testsuite/23_containers/vector/moveable.cc
Normal file
72
libstdc++-v3/testsuite/23_containers/vector/moveable.cc
Normal file
@ -0,0 +1,72 @@
|
||||
// { 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;
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
// { 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;
|
||||
}
|
120
libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc
Normal file
120
libstdc++-v3/testsuite/25_algorithms/heap/moveable.cc
Normal file
@ -0,0 +1,120 @@
|
||||
// { 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;
|
||||
}
|
76
libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc
Normal file
76
libstdc++-v3/testsuite/25_algorithms/nth_element/moveable.cc
Normal file
@ -0,0 +1,76 @@
|
||||
// { 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;
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
// { 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.1.3 [lib.partial.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>
|
||||
|
||||
using __gnu_test::test_container;
|
||||
using __gnu_test::random_access_iterator_wrapper;
|
||||
using __gnu_test::rvalstruct;
|
||||
using std::partial_sort;
|
||||
|
||||
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);
|
||||
partial_sort(con.begin(), con.it(3), con.end());
|
||||
VERIFY(array[0].val == 0 && array[1].val == 1 && array[2].val == 2);
|
||||
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);
|
||||
partial_sort(con.begin(), con.it(3), con.end());
|
||||
VERIFY(array[0].val == 0 && array[1].val == 1 && array[2].val == 2);
|
||||
for(int i = 0; i < 7; ++i)
|
||||
VERIFY(array[i].valid);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
}
|
@ -50,24 +50,9 @@ test01()
|
||||
for (const int* i = m; i < s1 + N; ++i) VERIFY(!pred(*i));
|
||||
}
|
||||
|
||||
// 25.2.12 stable_partition()
|
||||
void
|
||||
test02()
|
||||
{
|
||||
using std::stable_partition;
|
||||
|
||||
int s1[N];
|
||||
std::copy(A, A + N, s1);
|
||||
|
||||
stable_partition(s1, s1 + N, Pred());
|
||||
VERIFY(std::equal(s1, s1 + N, B));
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
|
||||
return 0;
|
||||
}
|
90
libstdc++-v3/testsuite/25_algorithms/partition/moveable.cc
Normal file
90
libstdc++-v3/testsuite/25_algorithms/partition/moveable.cc
Normal file
@ -0,0 +1,90 @@
|
||||
// { 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.2.12 [lib.alg.partitions] Partitions.
|
||||
|
||||
#undef _GLIBCXX_CONCEPT_CHECKS
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_rvalref.h>
|
||||
#include <testsuite_iterators.h>
|
||||
|
||||
using __gnu_test::test_container;
|
||||
using __gnu_test::forward_iterator_wrapper;
|
||||
using __gnu_test::bidirectional_iterator_wrapper;
|
||||
using __gnu_test::rvalstruct;
|
||||
|
||||
typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer;
|
||||
typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer;
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
|
||||
const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
|
||||
struct Pred
|
||||
{
|
||||
bool
|
||||
operator()(const rvalstruct& x) const
|
||||
{ return (x.val % 2) == 0; }
|
||||
};
|
||||
|
||||
// 25.2.12 partition()
|
||||
void
|
||||
test01()
|
||||
{
|
||||
using std::partition;
|
||||
|
||||
rvalstruct farray[N];
|
||||
rvalstruct barray[N];
|
||||
|
||||
std::copy(A, A + N, farray);
|
||||
std::copy(A, A + N, barray);
|
||||
|
||||
Fcontainer fcon(farray, farray + N);
|
||||
Bcontainer bcon(barray, barray + N);
|
||||
|
||||
Pred pred;
|
||||
|
||||
VERIFY(partition(fcon.begin(), fcon.end(), pred).ptr - farray == N/2);
|
||||
for (const rvalstruct* i = farray; i < farray+N/2; ++i)
|
||||
VERIFY(pred(*i));
|
||||
|
||||
for (const rvalstruct* i = farray+N/2; i < farray + N; ++i)
|
||||
VERIFY(!pred(*i));
|
||||
|
||||
VERIFY(partition(bcon.begin(), bcon.end(), pred).ptr - barray == N/2);
|
||||
|
||||
for (const rvalstruct* i = barray; i < barray+N/2; ++i)
|
||||
VERIFY(pred(*i));
|
||||
for (const rvalstruct* i = barray+N/2; i < barray + N; ++i)
|
||||
VERIFY(!pred(*i));
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
68
libstdc++-v3/testsuite/25_algorithms/remove/moveable.cc
Normal file
68
libstdc++-v3/testsuite/25_algorithms/remove/moveable.cc
Normal file
@ -0,0 +1,68 @@
|
||||
// { 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.2.4 remove
|
||||
|
||||
#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::forward_iterator_wrapper;
|
||||
using __gnu_test::rvalstruct;
|
||||
|
||||
typedef test_container<rvalstruct, forward_iterator_wrapper> Container;
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
int intarray[] = {1};
|
||||
rvalstruct array[1];
|
||||
std::copy(intarray, intarray + 1, array);
|
||||
Container con(array, array + 1);
|
||||
rvalstruct remove_val0(0);
|
||||
rvalstruct remove_val1(1);
|
||||
VERIFY(std::remove(con.begin(), con.end(), remove_val0).ptr == array + 1);
|
||||
VERIFY(std::remove(con.begin(), con.end(), remove_val1).ptr == array);
|
||||
}
|
||||
|
||||
void
|
||||
test2()
|
||||
{
|
||||
int intarray[] = {0, 1, 0, 1, 0, 0, 1, 1};
|
||||
rvalstruct array[8];
|
||||
std::copy(intarray, intarray + 8, array);
|
||||
Container con(array, array + 8);
|
||||
rvalstruct remove_val(1);
|
||||
VERIFY(std::remove(con.begin(), con.end(), remove_val).ptr == array + 4);
|
||||
VERIFY(array[0].val == 0 && array[1].val == 0 && array[2].val == 0 &&
|
||||
array[3].val == 0);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
}
|
68
libstdc++-v3/testsuite/25_algorithms/remove_if/moveable.cc
Normal file
68
libstdc++-v3/testsuite/25_algorithms/remove_if/moveable.cc
Normal file
@ -0,0 +1,68 @@
|
||||
// { 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.2.4 remove
|
||||
|
||||
#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::forward_iterator_wrapper;
|
||||
using __gnu_test::rvalstruct;
|
||||
|
||||
typedef test_container<rvalstruct, forward_iterator_wrapper> Container;
|
||||
|
||||
bool equal1(rvalstruct& in) { return in.val == 1; }
|
||||
bool equal0(rvalstruct& in) { return in.val == 0; }
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
int intarray[] = {1};
|
||||
rvalstruct array[1];
|
||||
std::copy(intarray, intarray + 1, array);
|
||||
Container con(array, array + 1);
|
||||
VERIFY(std::remove_if(con.begin(), con.end(), equal0).ptr == array + 1);
|
||||
VERIFY(std::remove_if(con.begin(), con.end(), equal1).ptr == array);
|
||||
}
|
||||
|
||||
void
|
||||
test2()
|
||||
{
|
||||
int intarray[] = {0, 1, 0, 1, 0, 0, 1, 1};
|
||||
rvalstruct array[8];
|
||||
std::copy(intarray, intarray + 8, array);
|
||||
Container con(array, array + 8);
|
||||
VERIFY(std::remove_if(con.begin(), con.end(), equal1).ptr == array + 4);
|
||||
VERIFY(array[0] == 0 && array[1] == 0 && array[2] == 0 &&
|
||||
array[3] == 0);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
}
|
45
libstdc++-v3/testsuite/25_algorithms/reverse/moveable.cc
Normal file
45
libstdc++-v3/testsuite/25_algorithms/reverse/moveable.cc
Normal file
@ -0,0 +1,45 @@
|
||||
// { 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.
|
||||
|
||||
// 25.2.9 Reverse
|
||||
|
||||
#undef _GLIBCXX_CONCEPT_CHECKS
|
||||
|
||||
#include <algorithm>
|
||||
#include <testsuite_iterators.h>
|
||||
|
||||
using __gnu_test::bidirectional_iterator_wrapper;
|
||||
|
||||
class X
|
||||
{
|
||||
X();
|
||||
X(const X&);
|
||||
void operator=(const X&);
|
||||
};
|
||||
|
||||
void
|
||||
swap(X&, X&) { }
|
||||
|
||||
void
|
||||
test1(bidirectional_iterator_wrapper<X>& begin,
|
||||
bidirectional_iterator_wrapper<X>& end)
|
||||
{ std::reverse(begin, end); }
|
79
libstdc++-v3/testsuite/25_algorithms/rotate/moveable.cc
Normal file
79
libstdc++-v3/testsuite/25_algorithms/rotate/moveable.cc
Normal file
@ -0,0 +1,79 @@
|
||||
// { 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.2.10 rotate
|
||||
|
||||
// Tests rotate when an moveable class is used
|
||||
|
||||
#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::forward_iterator_wrapper;
|
||||
using __gnu_test::bidirectional_iterator_wrapper;
|
||||
using __gnu_test::random_access_iterator_wrapper;
|
||||
using __gnu_test::rvalstruct;
|
||||
|
||||
typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer;
|
||||
typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer;
|
||||
typedef test_container<rvalstruct, random_access_iterator_wrapper> Rcontainer;
|
||||
|
||||
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
int data[] = {1, 2, 3, 4, 5};
|
||||
rvalstruct array[5];
|
||||
std::copy(data, data + 5, array);
|
||||
Fcontainer fcon(array, array + 5);
|
||||
Bcontainer bcon(array, array + 5);
|
||||
Rcontainer rcon(array, array + 5);
|
||||
|
||||
std::rotate(fcon.begin(), fcon.it(2), fcon.end());
|
||||
VERIFY(array[0].val == 3 && array[1].val == 4 && array[2].val == 5 &&
|
||||
array[3].val == 1 && array[4].val == 2);
|
||||
for(int i=0;i<5;i++)
|
||||
VERIFY(array[i].valid == true);
|
||||
|
||||
std::rotate(bcon.begin(), bcon.it(2), bcon.end());
|
||||
VERIFY(array[0].val == 5 && array[1].val == 1 && array[2].val == 2 &&
|
||||
array[3].val == 3 && array[4].val == 4);
|
||||
for(int i=0;i<5;i++)
|
||||
VERIFY(array[i].valid);
|
||||
|
||||
std::rotate(rcon.begin(), rcon.it(2), rcon.end());
|
||||
VERIFY(array[0].val == 2 && array[1].val == 3 && array[2].val == 4 &&
|
||||
array[3].val == 5 && array[4].val == 1);
|
||||
for(int i=0;i<5;i++)
|
||||
VERIFY(array[i].valid);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test1();
|
||||
}
|
@ -24,9 +24,11 @@
|
||||
|
||||
using __gnu_test::test_container;
|
||||
using __gnu_test::forward_iterator_wrapper;
|
||||
using __gnu_test::random_access_iterator_wrapper;
|
||||
using std::search;
|
||||
|
||||
typedef test_container<int, forward_iterator_wrapper> Container;
|
||||
typedef test_container<int, random_access_iterator_wrapper> RAcontainer;
|
||||
int array1[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
|
||||
int array2[] = {0, 0, 0};
|
||||
|
||||
@ -101,6 +103,53 @@ test6()
|
||||
== array3 + 6);
|
||||
}
|
||||
|
||||
bool
|
||||
lexstep(int* start, int length)
|
||||
{
|
||||
int i = 0;
|
||||
int carry = 1;
|
||||
while(i < length && carry)
|
||||
{
|
||||
if(start[i] == 1)
|
||||
start[i] = 0;
|
||||
else
|
||||
{
|
||||
start[i] = 1;
|
||||
carry = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return !carry;
|
||||
}
|
||||
|
||||
void test7()
|
||||
{
|
||||
int array1[6];
|
||||
int array2[6];
|
||||
for(int length1 = 0; length1 < 6; length1++)
|
||||
{
|
||||
for(int length2 = 0; length2 < 6; length2++)
|
||||
{
|
||||
std::fill_n(array1, length1, 0);
|
||||
while(lexstep(array1, length1))
|
||||
{
|
||||
std::fill_n(array2, length2, 0);
|
||||
while(lexstep(array2, length2))
|
||||
{
|
||||
Container con1(array1, array1 + length1);
|
||||
Container con2(array2, array2 + length2);
|
||||
RAcontainer rcon1(array1, array1 + length1);
|
||||
RAcontainer rcon2(array2, array2 + length2);
|
||||
VERIFY(search(con1.begin(), con1.end(), con2.begin(),
|
||||
con2.end()).ptr ==
|
||||
search(rcon1.begin(), rcon1.end(), rcon2.begin(),
|
||||
rcon2.end()).ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -110,4 +159,5 @@ main()
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
}
|
||||
|
@ -25,14 +25,33 @@
|
||||
|
||||
using __gnu_test::forward_iterator_wrapper;
|
||||
|
||||
struct S1 { };
|
||||
struct S2 { };
|
||||
struct T1 { };
|
||||
struct T2 { };
|
||||
|
||||
struct S1
|
||||
{
|
||||
S1(T1) { }
|
||||
};
|
||||
|
||||
struct S2 {
|
||||
S2(T2) { }
|
||||
};
|
||||
|
||||
bool
|
||||
operator==(const S1&, const S2&) {return true;}
|
||||
|
||||
struct X1 { };
|
||||
struct X2 { };
|
||||
struct V1 { };
|
||||
struct V2 { };
|
||||
|
||||
struct X1
|
||||
{
|
||||
X1(V1) { };
|
||||
};
|
||||
|
||||
struct X2
|
||||
{
|
||||
X2(V2) { };
|
||||
};
|
||||
|
||||
bool
|
||||
predicate(const X1&, const X2&) {return true;}
|
||||
@ -41,6 +60,14 @@ forward_iterator_wrapper<S1>
|
||||
test1(forward_iterator_wrapper<S1>& s1, forward_iterator_wrapper<S2>& s2)
|
||||
{ return std::search(s1, s1, s2, s2); }
|
||||
|
||||
forward_iterator_wrapper<T1>
|
||||
test2(forward_iterator_wrapper<T1>& s1, forward_iterator_wrapper<T2>& s2)
|
||||
{ return std::search(s1, s1, s2, s2); }
|
||||
|
||||
forward_iterator_wrapper<X1>
|
||||
test2(forward_iterator_wrapper<X1>& x1, forward_iterator_wrapper<X2>& x2)
|
||||
test3(forward_iterator_wrapper<X1>& x1, forward_iterator_wrapper<X2>& x2)
|
||||
{ return std::search(x1, x1, x2, x2, predicate); }
|
||||
|
||||
forward_iterator_wrapper<V1>
|
||||
test4(forward_iterator_wrapper<V1>& x1, forward_iterator_wrapper<V2>& x2)
|
||||
{ return std::search(x1, x1, x2, x2, predicate); }
|
||||
|
64
libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc
Normal file
64
libstdc++-v3/testsuite/25_algorithms/sort/moveable.cc
Normal file
@ -0,0 +1,64 @@
|
||||
// { 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.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;
|
||||
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};
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
56
libstdc++-v3/testsuite/25_algorithms/stable_partition/1.cc
Normal file
56
libstdc++-v3/testsuite/25_algorithms/stable_partition/1.cc
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2001 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// 25.2.12 [lib.alg.partitions] Partitions.
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
|
||||
const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
|
||||
struct Pred
|
||||
{
|
||||
bool
|
||||
operator()(const int& x) const
|
||||
{ return (x % 2) == 0; }
|
||||
};
|
||||
|
||||
// 25.2.12 stable_partition()
|
||||
void
|
||||
test02()
|
||||
{
|
||||
using std::stable_partition;
|
||||
|
||||
int s1[N];
|
||||
std::copy(A, A + N, s1);
|
||||
|
||||
stable_partition(s1, s1 + N, Pred());
|
||||
VERIFY(std::equal(s1, s1 + N, B));
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test02();
|
||||
return 0;
|
||||
}
|
45
libstdc++-v3/testsuite/25_algorithms/swap_ranges/moveable.cc
Normal file
45
libstdc++-v3/testsuite/25_algorithms/swap_ranges/moveable.cc
Normal file
@ -0,0 +1,45 @@
|
||||
// { 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.
|
||||
|
||||
// 25.2.4 Swap Ranges
|
||||
|
||||
#undef _GLIBCXX_CONCEPT_CHECKS
|
||||
|
||||
#include <algorithm>
|
||||
#include <testsuite_iterators.h>
|
||||
|
||||
using __gnu_test::forward_iterator_wrapper;
|
||||
|
||||
class X
|
||||
{
|
||||
X();
|
||||
X(const X&);
|
||||
void operator=(const X&);
|
||||
};
|
||||
|
||||
void
|
||||
swap(X&, X&) { }
|
||||
|
||||
void
|
||||
test1(forward_iterator_wrapper<X>& begin, forward_iterator_wrapper<X>& end,
|
||||
forward_iterator_wrapper<X>& begin2)
|
||||
{ std::swap_ranges(begin, end, begin2); }
|
74
libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc
Normal file
74
libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc
Normal file
@ -0,0 +1,74 @@
|
||||
// { 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.2.8 [lib.alg.unique] Unique
|
||||
|
||||
#undef _GLIBCXX_CONCEPT_CHECKS
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_iterators.h>
|
||||
#include <testsuite_rvalref.h>
|
||||
|
||||
using __gnu_test::test_container;
|
||||
using __gnu_test::forward_iterator_wrapper;
|
||||
using __gnu_test::rvalstruct;
|
||||
|
||||
typedef test_container<rvalstruct, forward_iterator_wrapper> Container;
|
||||
|
||||
void test01()
|
||||
{
|
||||
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()).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()).ptr - T2 == 8);
|
||||
for(int i = 0; i < 8; ++i)
|
||||
VERIFY(T2[i].val == B1[i]);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -79,3 +79,12 @@ proc dg-require-time { args } {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
proc dg-require-rvalref { args } {
|
||||
if { ![ check_v3_target_rvalref ] } {
|
||||
upvar dg-do-what dg-do-what
|
||||
set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -762,6 +762,61 @@ proc check_v3_target_time { } {
|
||||
return $et_time_saved
|
||||
}
|
||||
|
||||
proc check_v3_target_rvalref { } {
|
||||
global et_rvalref_saved
|
||||
global et_rvalref_target_name
|
||||
global tool
|
||||
|
||||
if { ![info exists et_rvalref_target_name] } {
|
||||
set et_rvalref_target_name ""
|
||||
}
|
||||
|
||||
# If the target has changed since we set the cached value, clear it.
|
||||
set current_target [current_target_name]
|
||||
if { $current_target != $et_rvalref_target_name } {
|
||||
verbose "check_v3_target_rvalref: `$et_rvalref_target_name'" 2
|
||||
set et_rvalref_target_name $current_target
|
||||
if [info exists et_rvalref_saved] {
|
||||
verbose "check_v3_target_rvalref: removing cached result" 2
|
||||
unset et_rvalref_saved
|
||||
}
|
||||
}
|
||||
|
||||
if [info exists et_rvalref_saved] {
|
||||
verbose "check_v3_target_rvalref: using cached result" 2
|
||||
} else {
|
||||
set et_rvalref_saved 0
|
||||
|
||||
# Set up and compile a C++ test program that tries to use
|
||||
# the library components of rval references
|
||||
set src rvalref[pid].cc
|
||||
set exe rvalref[pid].x
|
||||
|
||||
set f [open $src "w"]
|
||||
puts $f "#include <iterator>"
|
||||
puts $f "#include <utility>"
|
||||
puts $f "using std::move;"
|
||||
puts $f "using std::identity;"
|
||||
puts $f "using std::forward;"
|
||||
puts $f "using std::move_iterator;"
|
||||
puts $f "using std::make_move_iterator;"
|
||||
close $f
|
||||
|
||||
set lines [v3_target_compile $src $exe executable ""]
|
||||
file delete $src
|
||||
|
||||
if [string match "" $lines] {
|
||||
# No error message, compilation succeeded.
|
||||
verbose "check_v3_target_rvalref: compilation succeeded" 2
|
||||
remote_file build delete $exe
|
||||
set et_rvalref_saved 1
|
||||
} else {
|
||||
verbose "check_v3_target_rvalref: compilation failed" 2
|
||||
}
|
||||
}
|
||||
return $et_rvalref_saved
|
||||
}
|
||||
|
||||
proc check_v3_target_namedlocale { } {
|
||||
global et_namedlocale_saved
|
||||
global et_namedlocale_target_name
|
||||
|
194
libstdc++-v3/testsuite/util/testsuite_rvalref.h
Normal file
194
libstdc++-v3/testsuite/util/testsuite_rvalref.h
Normal file
@ -0,0 +1,194 @@
|
||||
// -*- C++ -*-
|
||||
// Testing utilities for the rvalue reference.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#ifndef _GLIBCXX_TESTSUITE_RVALREF_H
|
||||
#define _GLIBCXX_TESTSUITE_RVALREF_H 1
|
||||
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
namespace __gnu_test
|
||||
{
|
||||
|
||||
// This class is designed to test libstdc++'s template-based rvalue
|
||||
// reference support. It should fail at compile-time if there is an attempt
|
||||
// to copy it (although see note just below).
|
||||
class rvalstruct
|
||||
{
|
||||
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;
|
||||
|
||||
rvalstruct() : valid(false)
|
||||
{ }
|
||||
|
||||
rvalstruct(int inval) : val(inval), valid(true)
|
||||
{ }
|
||||
|
||||
rvalstruct&
|
||||
operator=(int newval)
|
||||
{
|
||||
VERIFY(valid == false);
|
||||
val = newval;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
rvalstruct(rvalstruct&& in)
|
||||
{
|
||||
VERIFY(in.valid == true);
|
||||
val = in.val;
|
||||
in.valid = false;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
rvalstruct&
|
||||
operator=(rvalstruct&& in)
|
||||
{
|
||||
VERIFY(in.valid == true);
|
||||
val = in.val;
|
||||
in.valid = false;
|
||||
valid = true;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
operator==(const rvalstruct& lhs, const rvalstruct& rhs)
|
||||
{ return lhs.val == rhs.val; }
|
||||
|
||||
bool
|
||||
operator<(const rvalstruct& lhs, const rvalstruct& rhs)
|
||||
{ return lhs.val < rhs.val; }
|
||||
|
||||
void
|
||||
swap(rvalstruct& lhs, rvalstruct& rhs)
|
||||
{
|
||||
VERIFY(lhs.valid && rhs.valid);
|
||||
int temp = lhs.val;
|
||||
lhs.val = rhs.val;
|
||||
rhs.val = temp;
|
||||
}
|
||||
|
||||
// This is a moveable class which copies how many times it is copied.
|
||||
// This is mainly of use in the containers, where the an element inserted
|
||||
// into a container has to be copied once to get there, but we want to check
|
||||
// nothing else is copied.
|
||||
struct copycounter
|
||||
{
|
||||
static int copycount;
|
||||
int val;
|
||||
bool valid;
|
||||
|
||||
copycounter() : val(0), valid(true)
|
||||
{ }
|
||||
|
||||
copycounter(int inval) : val(inval), valid(true)
|
||||
{ }
|
||||
|
||||
copycounter(const copycounter& in) : val(in.val), valid(true)
|
||||
{
|
||||
VERIFY(in.valid == true);
|
||||
++copycount;
|
||||
}
|
||||
|
||||
copycounter(copycounter&& in)
|
||||
{
|
||||
VERIFY(in.valid == true);
|
||||
val = in.val;
|
||||
in.valid = false;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
copycounter&
|
||||
operator=(int newval)
|
||||
{
|
||||
val = newval;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
bool
|
||||
operator=(const copycounter& in)
|
||||
{
|
||||
VERIFY(in.valid == true);
|
||||
++copycount;
|
||||
val = in.val;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
copycounter&
|
||||
operator=(copycounter&& in)
|
||||
{
|
||||
VERIFY(in.valid == true);
|
||||
val = in.val;
|
||||
in.valid = false;
|
||||
valid = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~copycounter()
|
||||
{ valid = false; }
|
||||
};
|
||||
|
||||
int copycounter::copycount = 0;
|
||||
|
||||
bool
|
||||
operator==(const copycounter& lhs, const copycounter& rhs)
|
||||
{ return lhs.val == rhs.val; }
|
||||
|
||||
bool
|
||||
operator<(const copycounter& lhs, const copycounter& rhs)
|
||||
{ return lhs.val < rhs.val; }
|
||||
|
||||
void
|
||||
swap(copycounter& lhs, copycounter& rhs)
|
||||
{
|
||||
VERIFY(lhs.valid && rhs.valid);
|
||||
int temp = lhs.val;
|
||||
lhs.val = rhs.val;
|
||||
rhs.val = temp;
|
||||
}
|
||||
|
||||
}; // namespace __gnu_test
|
||||
|
||||
#endif // _GLIBCXX_TESTSUITE_TR1_H
|
Loading…
Reference in New Issue
Block a user