check_construct_destroy.h: New.

2009-06-17  Benjamin Kosnik  <bkoz@redhat.com>

	* testsuite/23_containers/list/check_construct_destroy.h: New.
	Move test logic here.
	* testsuite/23_containers/list/moveable.h: Same.
	* testsuite/23_containers/list/modifiers/insert/25288.h: Same.
	* testsuite/23_containers/list/modifiers/1.h: Same.
	* testsuite/23_containers/list/modifiers/2.h: Same.
	* testsuite/23_containers/list/modifiers/3.h: Same.
	* testsuite/23_containers/list/modifiers/swap/1.h: Same.
	* testsuite/23_containers/list/modifiers/swap/2.h: Same.
	* testsuite/23_containers/list/modifiers/swap/3.h: Same.
	* testsuite/23_containers/list/operations/1.h: Same.
	* testsuite/23_containers/list/operations/2.h: Same.
	* testsuite/23_containers/list/operations/3.h: Same.
	* testsuite/23_containers/list/operations/4.h: Same.
	* testsuite/23_containers/list/operations/5.h: Same.
	* testsuite/23_containers/list/capacity/1.h: Same.
	* testsuite/23_containers/list/init-list.h: Same.
	* testsuite/23_containers/list/cons/1.h: Same.
	* testsuite/23_containers/list/cons/2.h: Same.
	* testsuite/23_containers/list/cons/3.h: Same.
	* testsuite/23_containers/list/cons/4.h: Same.
	* testsuite/23_containers/list/cons/5.h: Same.
	* testsuite/23_containers/list/cons/6.h: Same.
	* testsuite/23_containers/list/cons/7.h: Same.
	* testsuite/23_containers/list/cons/8.h: Same.
	* testsuite/23_containers/list/cons/9.h: Same.
	* testsuite/23_containers/list/cons/clear_allocator.h: Same.
	* testsuite/23_containers/list/modifiers/insert/25288.cc: Include test
	header.
	* testsuite/23_containers/list/modifiers/1.cc: Same.
	* testsuite/23_containers/list/modifiers/2.cc: Same.
	* testsuite/23_containers/list/modifiers/3.cc: Same.
	* testsuite/23_containers/list/modifiers/swap/1.cc: Same.
	* testsuite/23_containers/list/modifiers/swap/2.cc: Same.
	* testsuite/23_containers/list/modifiers/swap/3.cc: Same.
	* testsuite/23_containers/list/operations/1.cc: Same.
	* testsuite/23_containers/list/operations/2.cc: Same.
	* testsuite/23_containers/list/operations/3.cc: Same.
	* testsuite/23_containers/list/operations/4.cc: Same.
	* testsuite/23_containers/list/operations/5.cc: Same.
	* testsuite/23_containers/list/capacity/1.cc: Same.
	* testsuite/23_containers/list/init-list.cc: Same.
	* testsuite/23_containers/list/cons/1.cc: Same.
	* testsuite/23_containers/list/cons/2.cc: Same.
	* testsuite/23_containers/list/cons/3.cc: Same.
	* testsuite/23_containers/list/cons/4.cc: Same.
	* testsuite/23_containers/list/cons/5.cc: Same.
	* testsuite/23_containers/list/cons/6.cc: Same.
	* testsuite/23_containers/list/cons/7.cc: Same.
	* testsuite/23_containers/list/cons/8.cc: Same.
	* testsuite/23_containers/list/cons/9.cc: Same.
	* testsuite/23_containers/list/cons/clear_allocator.cc: Same.
	* testsuite/23_containers/list/check_construct_destroy.cc: Same.
	* testsuite/23_containers/list/moveable.cc: Same.

From-SVN: r148644
This commit is contained in:
Benjamin Kosnik 2009-06-18 01:40:44 +00:00 committed by Benjamin Kosnik
parent 6bec4135eb
commit a9a51750b9
53 changed files with 2116 additions and 1582 deletions

View File

@ -1,3 +1,60 @@
2009-06-17 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/23_containers/list/check_construct_destroy.h: New.
Move test logic here.
* testsuite/23_containers/list/moveable.h: Same.
* testsuite/23_containers/list/modifiers/insert/25288.h: Same.
* testsuite/23_containers/list/modifiers/1.h: Same.
* testsuite/23_containers/list/modifiers/2.h: Same.
* testsuite/23_containers/list/modifiers/3.h: Same.
* testsuite/23_containers/list/modifiers/swap/1.h: Same.
* testsuite/23_containers/list/modifiers/swap/2.h: Same.
* testsuite/23_containers/list/modifiers/swap/3.h: Same.
* testsuite/23_containers/list/operations/1.h: Same.
* testsuite/23_containers/list/operations/2.h: Same.
* testsuite/23_containers/list/operations/3.h: Same.
* testsuite/23_containers/list/operations/4.h: Same.
* testsuite/23_containers/list/operations/5.h: Same.
* testsuite/23_containers/list/capacity/1.h: Same.
* testsuite/23_containers/list/init-list.h: Same.
* testsuite/23_containers/list/cons/1.h: Same.
* testsuite/23_containers/list/cons/2.h: Same.
* testsuite/23_containers/list/cons/3.h: Same.
* testsuite/23_containers/list/cons/4.h: Same.
* testsuite/23_containers/list/cons/5.h: Same.
* testsuite/23_containers/list/cons/6.h: Same.
* testsuite/23_containers/list/cons/7.h: Same.
* testsuite/23_containers/list/cons/8.h: Same.
* testsuite/23_containers/list/cons/9.h: Same.
* testsuite/23_containers/list/cons/clear_allocator.h: Same.
* testsuite/23_containers/list/modifiers/insert/25288.cc: Include test
header.
* testsuite/23_containers/list/modifiers/1.cc: Same.
* testsuite/23_containers/list/modifiers/2.cc: Same.
* testsuite/23_containers/list/modifiers/3.cc: Same.
* testsuite/23_containers/list/modifiers/swap/1.cc: Same.
* testsuite/23_containers/list/modifiers/swap/2.cc: Same.
* testsuite/23_containers/list/modifiers/swap/3.cc: Same.
* testsuite/23_containers/list/operations/1.cc: Same.
* testsuite/23_containers/list/operations/2.cc: Same.
* testsuite/23_containers/list/operations/3.cc: Same.
* testsuite/23_containers/list/operations/4.cc: Same.
* testsuite/23_containers/list/operations/5.cc: Same.
* testsuite/23_containers/list/capacity/1.cc: Same.
* testsuite/23_containers/list/init-list.cc: Same.
* testsuite/23_containers/list/cons/1.cc: Same.
* testsuite/23_containers/list/cons/2.cc: Same.
* testsuite/23_containers/list/cons/3.cc: Same.
* testsuite/23_containers/list/cons/4.cc: Same.
* testsuite/23_containers/list/cons/5.cc: Same.
* testsuite/23_containers/list/cons/6.cc: Same.
* testsuite/23_containers/list/cons/7.cc: Same.
* testsuite/23_containers/list/cons/8.cc: Same.
* testsuite/23_containers/list/cons/9.cc: Same.
* testsuite/23_containers/list/cons/clear_allocator.cc: Same.
* testsuite/23_containers/list/check_construct_destroy.cc: Same.
* testsuite/23_containers/list/moveable.cc: Same.
2009-06-17 Tom Tromey <tromey@redhat.com>
* python/hook.in: Do not fail when there is no current objfile.

View File

@ -15,51 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.2 list capacity [lib.list.capacity]
#include "1.h"
#include <list>
#include <testsuite_hooks.h>
// This test verifies the following.
//
// 23.2.2 bool empty() const
// 23.2.2 size_type size() const
// 23.2.2 iterator begin()
// 23.2.2 iterator end()
// 23.2.2.3 void push_back(const T&)
// 23.2.2 size_type max_size() const
// 23.2.2.2 void resize(size_type s, T c = T())
//
template<typename _Tp>
void
capacity01()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator_type;
list_type list0101;
VERIFY(list0101.empty());
VERIFY(list0101.size() == 0);
list0101.push_back(1);
VERIFY(!list0101.empty());
VERIFY(list0101.size() == 1);
list0101.resize(3, 2);
VERIFY(!list0101.empty());
VERIFY(list0101.size() == 3);
iterator_type i = list0101.begin();
VERIFY(*i == 1); ++i;
VERIFY(*i == 2); ++i;
VERIFY(*i == 2); ++i;
VERIFY(i == list0101.end());
list0101.resize(0);
VERIFY(list0101.empty());
VERIFY(list0101.size() == 0);
}
int
main()

View File

@ -0,0 +1,61 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.2 list capacity [lib.list.capacity]
#include <testsuite_hooks.h>
// This test verifies the following.
//
// 23.2.2 bool empty() const
// 23.2.2 size_type size() const
// 23.2.2 iterator begin()
// 23.2.2 iterator end()
// 23.2.2.3 void push_back(const T&)
// 23.2.2 size_type max_size() const
// 23.2.2.2 void resize(size_type s, T c = T())
//
template<typename _Tp>
void
capacity01()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator_type;
list_type list0101;
VERIFY(list0101.empty());
VERIFY(list0101.size() == 0);
list0101.push_back(1);
VERIFY(!list0101.empty());
VERIFY(list0101.size() == 1);
list0101.resize(3, 2);
VERIFY(!list0101.empty());
VERIFY(list0101.size() == 3);
iterator_type i = list0101.begin();
VERIFY(*i == 1); ++i;
VERIFY(*i == 2); ++i;
VERIFY(*i == 2); ++i;
VERIFY(i == list0101.end());
list0101.resize(0);
VERIFY(list0101.empty());
VERIFY(list0101.size() == 0);
}

View File

@ -18,70 +18,12 @@
// <http://www.gnu.org/licenses/>.
//
#include "check_construct_destroy.h"
#include <list>
#include <iterator>
#include <testsuite_allocator.h>
template<typename _Tp>
bool
construct_destroy()
{
typedef _Tp list_type;
typedef typename list_type::iterator iterator_type;
using namespace __gnu_test;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
tracker_allocator_counter::reset();
{
list_type c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
}
ok = check_construct_destroy("empty container", 0, 0) && ok;
tracker_allocator_counter::reset();
{
list_type c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
}
ok = check_construct_destroy("Construct from range", 10, 10) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
c.insert(c.begin(), arr10[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
ok = check_construct_destroy("Insert element", 1, 11) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
iterator_type i5 = c.begin();
std::advance(i5, 5);
c.insert(i5, arr10, arr10+3);
ok = check_construct_destroy("Insert short range", 3, 0) && ok;
}
ok = check_construct_destroy("Insert short range", 3, 13) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
iterator_type i7 = c.begin();
std::advance(i7, 5);
c.insert(i7, arr10, arr10+10);
ok = check_construct_destroy("Insert long range", 10, 0) && ok;
}
ok = check_construct_destroy("Insert long range", 10, 20) && ok;
return ok ? 0 : 1;
}
int main()
{
construct_destroy<std::list<int, __gnu_test::tracker_allocator<int> > >();
typedef __gnu_test::tracker_allocator<int> allocator_type;
construct_destroy<std::list<int, allocator_type> >();
return 0;
}

View File

@ -0,0 +1,79 @@
// 2004-07-26 Matt Austern <austern@apple.com>
//
// Copyright (C) 2003, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
#include <iterator>
#include <testsuite_allocator.h>
template<typename _Tp>
bool
construct_destroy()
{
typedef _Tp list_type;
typedef typename list_type::iterator iterator_type;
using namespace __gnu_test;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
tracker_allocator_counter::reset();
{
list_type c;
ok = check_construct_destroy("empty container", 0, 0) && ok;
}
ok = check_construct_destroy("empty container", 0, 0) && ok;
tracker_allocator_counter::reset();
{
list_type c(arr10, arr10 + 10);
ok = check_construct_destroy("Construct from range", 10, 0) && ok;
}
ok = check_construct_destroy("Construct from range", 10, 10) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
c.insert(c.begin(), arr10[0]);
ok = check_construct_destroy("Insert element", 1, 0) && ok;
}
ok = check_construct_destroy("Insert element", 1, 11) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
iterator_type i5 = c.begin();
std::advance(i5, 5);
c.insert(i5, arr10, arr10+3);
ok = check_construct_destroy("Insert short range", 3, 0) && ok;
}
ok = check_construct_destroy("Insert short range", 3, 13) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
iterator_type i7 = c.begin();
std::advance(i7, 5);
c.insert(i7, arr10, arr10+10);
ok = check_construct_destroy("Insert long range", 10, 0) && ok;
}
ok = check_construct_destroy("Insert long range", 10, 20) && ok;
return ok ? 0 : 1;
}

View File

@ -15,55 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "1.h"
#include <list>
#include <testsuite_hooks.h>
// A nontrivial type.
template<typename T>
struct A { };
// Another nontrivial type
struct B { };
// Default constructor, basic properties
//
// This test verifies the following.
// 23.2.2.1 explicit list(const a& = Allocator())
// 23.1 (7) iterator behaviour of empty containers
// 23.2.2 iterator begin()
// 23.2.2 iterator end()
// 23.2.2 size_type size() const
// 23.2.2 existence of required typedefs
//
template<typename _Tp>
void
cons01()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type list0101;
VERIFY(list0101.begin() == list0101.end());
VERIFY(list0101.size() == 0);
// check type definitions -- will fail compile if missing
typedef typename list_type::reference reference;
typedef typename list_type::const_reference const_reference;
typedef typename list_type::iterator iterator;
typedef typename list_type::const_iterator const_iterator;
typedef typename list_type::size_type size_type;
typedef typename list_type::difference_type difference_type;
typedef typename list_type::value_type value_type;
typedef typename list_type::allocator_type allocator_type;
typedef typename list_type::pointer pointer;
typedef typename list_type::const_pointer const_pointer;
typedef typename list_type::reverse_iterator reverse_iterator;
typedef typename list_type::const_reverse_iterator const_reverse_iterator;
// allocator checks?
}
int main()
{

View File

@ -0,0 +1,63 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// A nontrivial type.
template<typename T>
struct A { };
// Another nontrivial type
struct B { };
// Default constructor, basic properties
//
// This test verifies the following.
// 23.2.2.1 explicit list(const a& = Allocator())
// 23.1 (7) iterator behaviour of empty containers
// 23.2.2 iterator begin()
// 23.2.2 iterator end()
// 23.2.2 size_type size() const
// 23.2.2 existence of required typedefs
//
template<typename _Tp>
void
cons01()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type list0101;
VERIFY(list0101.begin() == list0101.end());
VERIFY(list0101.size() == 0);
// check type definitions -- will fail compile if missing
typedef typename list_type::reference reference;
typedef typename list_type::const_reference const_reference;
typedef typename list_type::iterator iterator;
typedef typename list_type::const_iterator const_iterator;
typedef typename list_type::size_type size_type;
typedef typename list_type::difference_type difference_type;
typedef typename list_type::value_type value_type;
typedef typename list_type::allocator_type allocator_type;
typedef typename list_type::pointer pointer;
typedef typename list_type::const_pointer const_pointer;
typedef typename list_type::reverse_iterator reverse_iterator;
typedef typename list_type::const_reverse_iterator const_reverse_iterator;
}

View File

@ -15,67 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "2.h"
#include <list>
#include <testsuite_hooks.h>
// A nontrivial type.
template<typename T>
struct A { };
// Another nontrivial type
struct B { };
// Fill constructor
//
// This test verifies the following.
// 23.2.2.1 explicit list(size_type n, const T& v = T(), const a& = Allocator())
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons021()
{
bool test __attribute__((unused)) = true;
const std::size_t LIST_SIZE = 5;
const int INIT_VALUE = 7;
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
// default value
list_type list0202(LIST_SIZE);
for (i = list0202.begin(), count = 0;
i != list0202.end();
++i, ++count)
VERIFY(*i == 0);
VERIFY(count == LIST_SIZE);
VERIFY(list0202.size() == LIST_SIZE);
// explicit value
list_type list0203(LIST_SIZE, INIT_VALUE);
for (i = list0203.begin(), count = 0;
i != list0203.end();
++i, ++count)
VERIFY(*i == INIT_VALUE);
VERIFY(count == LIST_SIZE);
VERIFY(list0203.size() == LIST_SIZE);
}
template<typename _Tp>
void
cons022()
{
// nontrivial value_type
typedef _Tp list_type;
const std::size_t LIST_SIZE = 5;
list_type list0201(LIST_SIZE);
}
int main()
{

View File

@ -0,0 +1,77 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// A nontrivial type.
template<typename T>
struct A { };
// Another nontrivial type
struct B { };
// Fill constructor
//
// This test verifies the following.
// 23.2.2.1 explicit list(size_type n, const T& v = T(), const a& = Allocator())
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons021()
{
bool test __attribute__((unused)) = true;
const std::size_t LIST_SIZE = 5;
const int INIT_VALUE = 7;
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
// default value
list_type list0202(LIST_SIZE);
for (i = list0202.begin(), count = 0;
i != list0202.end();
++i, ++count)
VERIFY(*i == 0);
VERIFY(count == LIST_SIZE);
VERIFY(list0202.size() == LIST_SIZE);
// explicit value
list_type list0203(LIST_SIZE, INIT_VALUE);
for (i = list0203.begin(), count = 0;
i != list0203.end();
++i, ++count)
VERIFY(*i == INIT_VALUE);
VERIFY(count == LIST_SIZE);
VERIFY(list0203.size() == LIST_SIZE);
}
template<typename _Tp>
void
cons022()
{
// nontrivial value_type
typedef _Tp list_type;
const std::size_t LIST_SIZE = 5;
list_type list0201(LIST_SIZE);
}

View File

@ -15,38 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "3.h"
#include <list>
#include <testsuite_hooks.h>
// A nontrivial type convertible from an int
struct C
{
C(int i) : i_(i) { }
bool operator==(const C& rhs) { return i_ == rhs.i_; }
int i_;
};
// Fill constructor disguised as a range constructor
template<typename _Tp>
void
cons03()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const std::size_t LIST_SIZE = 5;
const int INIT_VALUE = 7;
std::size_t count = 0;
list_type list0204(LIST_SIZE, INIT_VALUE);
iterator i = list0204.begin();
for (; i != list0204.end(); ++i, ++count)
VERIFY(*i == INIT_VALUE);
VERIFY(count == LIST_SIZE);
VERIFY(list0204.size() == LIST_SIZE);
}
int main()
{

View File

@ -0,0 +1,48 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// A nontrivial type convertible from an int
struct C
{
C(int i) : i_(i) { }
bool operator==(const C& rhs) { return i_ == rhs.i_; }
int i_;
};
// Fill constructor disguised as a range constructor
template<typename _Tp>
void
cons03()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const std::size_t LIST_SIZE = 5;
const int INIT_VALUE = 7;
std::size_t count = 0;
list_type list0204(LIST_SIZE, INIT_VALUE);
iterator i = list0204.begin();
for (; i != list0204.end(); ++i, ++count)
VERIFY(*i == INIT_VALUE);
VERIFY(count == LIST_SIZE);
VERIFY(list0204.size() == LIST_SIZE);
}

View File

@ -15,51 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "4.h"
#include <list>
#include <testsuite_hooks.h>
// Range constructor
//
// This test verifies the following.
// 23.2.2.1 template list(InputIterator f, InputIterator l,
// const Allocator& a = Allocator())
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons04()
{
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 std::size_t N = sizeof(A) / sizeof(int);
std::size_t count;
typedef std::list<int> list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
// construct from a dissimilar range
list_type list0301(A, A + N);
for (i = list0301.begin(), count = 0;
i != list0301.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0301.size() == N);
// construct from a similar range
list_type list0302(list0301.begin(), list0301.end());
for (i = list0302.begin(), count = 0;
i != list0302.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0302.size() == N);
}
int main()
{

View File

@ -0,0 +1,61 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// Range constructor
//
// This test verifies the following.
// 23.2.2.1 template list(InputIterator f, InputIterator l,
// const Allocator& a = Allocator())
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons04()
{
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 std::size_t N = sizeof(A) / sizeof(int);
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
// construct from a dissimilar range
list_type list0301(A, A + N);
for (i = list0301.begin(), count = 0;
i != list0301.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0301.size() == N);
// construct from a similar range
list_type list0302(list0301.begin(), list0301.end());
for (i = list0302.begin(), count = 0;
i != list0302.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0302.size() == N);
}

View File

@ -15,41 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "5.h"
#include <list>
#include <testsuite_hooks.h>
// Copy constructor
//
// This test verifies the following.
// 23.2.2.1 list(const list& x)
// 23.2.2 reverse_iterator rbegin()
// 23.2.2 reverse_iterator rend()
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons05()
{
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 std::size_t N = sizeof(A) / sizeof(int);
int count;
typedef _Tp list_type;
typedef typename list_type::reverse_iterator reverse_iterator;
reverse_iterator i;
list_type list0401(A, A + N);
list_type list0402(list0401);
for (i = list0401.rbegin(), count = N - 1;
i != list0401.rend();
++i, --count)
VERIFY(*i == A[count]);
VERIFY(count == -1);
VERIFY(list0401.size() == N);
}
int main()
{

View File

@ -0,0 +1,51 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// Copy constructor
//
// This test verifies the following.
// 23.2.2.1 list(const list& x)
// 23.2.2 reverse_iterator rbegin()
// 23.2.2 reverse_iterator rend()
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons05()
{
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 std::size_t N = sizeof(A) / sizeof(int);
int count;
typedef _Tp list_type;
typedef typename list_type::reverse_iterator reverse_iterator;
reverse_iterator i;
list_type list0401(A, A + N);
list_type list0402(list0401);
for (i = list0401.rbegin(), count = N - 1;
i != list0401.rend();
++i, --count)
VERIFY(*i == A[count]);
VERIFY(count == -1);
VERIFY(list0401.size() == N);
}

View File

@ -15,54 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "6.h"
#include <list>
#include <testsuite_hooks.h>
// Range assign
//
// This test verifies the following.
// 23.2.2.1 void assign(InputIterator f, InputIterator l)
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons06()
{
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[] = {101, 102, 103, 104, 105};
const std::size_t N = sizeof(A) / sizeof(int);
const std::size_t M = sizeof(B) / sizeof(int);
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
list_type list0501;
// make it bigger
list0501.assign(A, A + N);
for (i = list0501.begin(), count = 0;
i != list0501.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0501.size() == N);
// make it smaller
list0501.assign(B, B + M);
for (i = list0501.begin(), count = 0;
i != list0501.end();
++i, ++count)
VERIFY(*i == B[count]);
VERIFY(count == M);
VERIFY(list0501.size() == M);
}
int main()
{

View File

@ -0,0 +1,64 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// Range assign
//
// This test verifies the following.
// 23.2.2.1 void assign(InputIterator f, InputIterator l)
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons06()
{
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[] = {101, 102, 103, 104, 105};
const std::size_t N = sizeof(A) / sizeof(int);
const std::size_t M = sizeof(B) / sizeof(int);
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
list_type list0501;
// make it bigger
list0501.assign(A, A + N);
for (i = list0501.begin(), count = 0;
i != list0501.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0501.size() == N);
// make it smaller
list0501.assign(B, B + M);
for (i = list0501.begin(), count = 0;
i != list0501.end();
++i, ++count)
VERIFY(*i == B[count]);
VERIFY(count == M);
VERIFY(list0501.size() == M);
}

View File

@ -15,55 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "7.h"
#include <list>
#include <testsuite_hooks.h>
// Fill assign
//
// This test verifies the following.
// 23.2.2.1 void assign(size_type n, const T& v)
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons07()
{
bool test __attribute__((unused)) = true;
const std::size_t BIG_LIST_SIZE = 11;
const int BIG_INIT_VALUE = 7;
const std::size_t SMALL_LIST_SIZE = 5;
const int SMALL_INIT_VALUE = 17;
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
list_type list0601;
VERIFY(list0601.size() == 0);
// make it bigger
list0601.assign(BIG_LIST_SIZE, BIG_INIT_VALUE);
for (i = list0601.begin(), count = 0;
i != list0601.end();
++i, ++count)
VERIFY(*i == BIG_INIT_VALUE);
VERIFY(count == BIG_LIST_SIZE);
VERIFY(list0601.size() == BIG_LIST_SIZE);
// make it shrink
list0601.assign(SMALL_LIST_SIZE, SMALL_INIT_VALUE);
for (i = list0601.begin(), count = 0;
i != list0601.end();
++i, ++count)
VERIFY(*i == SMALL_INIT_VALUE);
VERIFY(count == SMALL_LIST_SIZE);
VERIFY(list0601.size() == SMALL_LIST_SIZE);
}
int main()
{

View File

@ -0,0 +1,65 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// Fill assign
//
// This test verifies the following.
// 23.2.2.1 void assign(size_type n, const T& v)
// 23.2.2 const_iterator begin() const
// 23.2.2 const_iterator end() const
// 23.2.2 size_type size() const
//
template<typename _Tp>
void
cons07()
{
bool test __attribute__((unused)) = true;
const std::size_t BIG_LIST_SIZE = 11;
const int BIG_INIT_VALUE = 7;
const std::size_t SMALL_LIST_SIZE = 5;
const int SMALL_INIT_VALUE = 17;
std::size_t count;
typedef _Tp list_type;
typedef typename list_type::const_iterator const_iterator;
const_iterator i;
list_type list0601;
VERIFY(list0601.size() == 0);
// make it bigger
list0601.assign(BIG_LIST_SIZE, BIG_INIT_VALUE);
for (i = list0601.begin(), count = 0;
i != list0601.end();
++i, ++count)
VERIFY(*i == BIG_INIT_VALUE);
VERIFY(count == BIG_LIST_SIZE);
VERIFY(list0601.size() == BIG_LIST_SIZE);
// make it shrink
list0601.assign(SMALL_LIST_SIZE, SMALL_INIT_VALUE);
for (i = list0601.begin(), count = 0;
i != list0601.end();
++i, ++count)
VERIFY(*i == SMALL_INIT_VALUE);
VERIFY(count == SMALL_LIST_SIZE);
VERIFY(list0601.size() == SMALL_LIST_SIZE);
}

View File

@ -15,41 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "8.h"
#include <list>
#include <testsuite_hooks.h>
// A nontrivial type convertible from an int
struct C
{
C(int i) : i_(i) { }
bool operator==(const C& rhs) { return i_ == rhs.i_; }
int i_;
};
// Fill Assignment disguised as a Range Assignment
template<typename _Tp>
void
cons08()
{
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
bool test __attribute__((unused)) = true;
const std::size_t LIST_SIZE = 5;
const int INIT_VALUE = 7;
std::size_t count = 0;
list_type list0604;
VERIFY(list0604.size() == 0);
list0604.assign(LIST_SIZE, INIT_VALUE);
iterator i = list0604.begin();
for (; i != list0604.end(); ++i, ++count)
VERIFY(*i == INIT_VALUE);
VERIFY(count == LIST_SIZE);
VERIFY(list0604.size() == LIST_SIZE);
}
int main()
{

View File

@ -0,0 +1,51 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// A nontrivial type convertible from an int
struct C
{
C(int i) : i_(i) { }
bool operator==(const C& rhs) { return i_ == rhs.i_; }
int i_;
};
// Fill Assignment disguised as a Range Assignment
template<typename _Tp>
void
cons08()
{
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
bool test __attribute__((unused)) = true;
const std::size_t LIST_SIZE = 5;
const int INIT_VALUE = 7;
std::size_t count = 0;
list_type list0604;
VERIFY(list0604.size() == 0);
list0604.assign(LIST_SIZE, INIT_VALUE);
iterator i = list0604.begin();
for (; i != list0604.end(); ++i, ++count)
VERIFY(*i == INIT_VALUE);
VERIFY(count == LIST_SIZE);
VERIFY(list0604.size() == LIST_SIZE);
}

View File

@ -15,49 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include "9.h"
#include <list>
#include <testsuite_hooks.h>
// Assignment operator
//
// This test verifies the following.
// 23.2.2 operator=(const list& x)
// 23.2.2 iterator begin()
// 23.2.2 iterator end()
// 23.2.2 size_type size() const
// 23.2.2 bool operator==(const list& x, const list& y)
//
template<typename _Tp>
void
cons09()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int A[] = {701, 702, 703, 704, 705};
const std::size_t N = sizeof(A) / sizeof(int);
std::size_t count;
iterator i;
list_type list0701(A, A + N);
VERIFY(list0701.size() == N);
list_type list0702;
VERIFY(list0702.size() == 0);
list0702 = list0701;
VERIFY(list0702.size() == N);
for (i = list0702.begin(), count = 0;
i != list0702.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0702 == list0701);
}
int main()
{

View File

@ -0,0 +1,59 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.1 list constructors, copy, and assignment
#include <testsuite_hooks.h>
// Assignment operator
//
// This test verifies the following.
// 23.2.2 operator=(const list& x)
// 23.2.2 iterator begin()
// 23.2.2 iterator end()
// 23.2.2 size_type size() const
// 23.2.2 bool operator==(const list& x, const list& y)
//
template<typename _Tp>
void
cons09()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int A[] = {701, 702, 703, 704, 705};
const std::size_t N = sizeof(A) / sizeof(int);
std::size_t count;
iterator i;
list_type list0701(A, A + N);
VERIFY(list0701.size() == N);
list_type list0702;
VERIFY(list0702.size() == 0);
list0702 = list0701;
VERIFY(list0702.size() == N);
for (i = list0702.begin(), count = 0;
i != list0702.end();
++i, ++count)
VERIFY(*i == A[count]);
VERIFY(count == N);
VERIFY(list0702 == list0701);
}

View File

@ -15,69 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include "clear_allocator.h"
#include <list>
#include <ext/new_allocator.h>
using namespace std;
using __gnu_cxx::new_allocator;
template<typename T>
class clear_alloc : public new_allocator<T>
{
public:
template <typename T1>
struct rebind
{ typedef clear_alloc<T1> other; };
virtual void clear() throw()
{ }
clear_alloc() throw()
{ }
clear_alloc(clear_alloc const&) throw() : new_allocator<T>()
{ }
template<typename T1>
clear_alloc(clear_alloc<T1> const&) throw()
{ }
virtual ~clear_alloc() throw()
{ this->clear(); }
T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0)
{
this->clear();
return new_allocator<T>::allocate(n, hint);
}
void deallocate(T *ptr, typename new_allocator<T>::size_type n)
{
this->clear();
new_allocator<T>::deallocate(ptr, n);
}
};
template<typename Container>
void Check_Container()
{
Container* pic = new Container;
int x = 230;
while (x--)
{
pic->push_back(x);
}
pic->get_allocator();
// The following has led to infinite recursions or cores.
pic->clear();
delete pic;
}
int main()
{

View File

@ -0,0 +1,78 @@
// Copyright (C) 2004, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/new_allocator.h>
using namespace std;
using __gnu_cxx::new_allocator;
template<typename T>
class clear_alloc : public new_allocator<T>
{
public:
template <typename T1>
struct rebind
{ typedef clear_alloc<T1> other; };
virtual void clear() throw()
{ }
clear_alloc() throw()
{ }
clear_alloc(clear_alloc const&) throw() : new_allocator<T>()
{ }
template<typename T1>
clear_alloc(clear_alloc<T1> const&) throw()
{ }
virtual ~clear_alloc() throw()
{ this->clear(); }
T* allocate(typename new_allocator<T>::size_type n, const void *hint = 0)
{
this->clear();
return new_allocator<T>::allocate(n, hint);
}
void deallocate(T *ptr, typename new_allocator<T>::size_type n)
{
this->clear();
new_allocator<T>::deallocate(ptr, n);
}
};
template<typename Container>
void Check_Container()
{
Container* pic = new Container;
int x = 230;
while (x--)
{
pic->push_back(x);
}
pic->get_allocator();
// The following has led to infinite recursions or cores.
pic->clear();
delete pic;
}

View File

@ -1,3 +1,5 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -16,56 +18,8 @@
// <http://www.gnu.org/licenses/>.
//
// { dg-options "-std=gnu++0x" }
#include "init-list.h"
#include <list>
#include <testsuite_allocator.h>
template<typename _Tp>
bool
init_list()
{
using namespace __gnu_test;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
tracker_allocator_counter::reset();
{
list_type c({ 2, 4, 1 });
ok = check_construct_destroy("Construct from init-list", 3, 0) && ok;
iterator i = c.begin();
ok &= (*i++ == 2);
ok &= (*i++ == 4);
}
ok = check_construct_destroy("Construct from init-list", 3, 3) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
iterator i = c.begin();
++i; ++i; ++i; ++i; ++i; ++i; ++i;
c.insert(i, { 234, 42, 1 });
ok = check_construct_destroy("Insert init-list", 3, 0) && ok;
ok &= (*--i == 1);
ok &= (*--i == 42);
}
ok = check_construct_destroy("Insert init-list", 3, 13) && ok;
{
list_type c;
tracker_allocator_counter::reset();
c = { 13, 0, 42 };
ok = check_construct_destroy("Assign init-list", 3, 0) && ok;
iterator i = c.begin();
ok &= (*i++ == 13);
}
ok = check_construct_destroy("Assign init-list", 3, 3) && ok;
return ok ? 0 : 1;
}
int main()
{

View File

@ -0,0 +1,65 @@
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
#include <testsuite_allocator.h>
template<typename _Tp>
bool
init_list()
{
using namespace __gnu_test;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
bool ok = true;
tracker_allocator_counter::reset();
{
list_type c({ 2, 4, 1 });
ok = check_construct_destroy("Construct from init-list", 3, 0) && ok;
iterator i = c.begin();
ok &= (*i++ == 2);
ok &= (*i++ == 4);
}
ok = check_construct_destroy("Construct from init-list", 3, 3) && ok;
{
list_type c(arr10, arr10 + 10);
tracker_allocator_counter::reset();
iterator i = c.begin();
++i; ++i; ++i; ++i; ++i; ++i; ++i;
c.insert(i, { 234, 42, 1 });
ok = check_construct_destroy("Insert init-list", 3, 0) && ok;
ok &= (*--i == 1);
ok &= (*--i == 42);
}
ok = check_construct_destroy("Insert init-list", 3, 13) && ok;
{
list_type c;
tracker_allocator_counter::reset();
c = { 13, 0, 42 };
ok = check_construct_destroy("Assign init-list", 3, 0) && ok;
iterator i = c.begin();
ok &= (*i++ == 13);
}
ok = check_construct_destroy("Assign init-list", 3, 3) && ok;
return ok ? 0 : 1;
}

View File

@ -15,103 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include "1.h"
#include <list>
#include <testsuite_hooks.h>
// range and fill insert/erase + clear
// missing: o fill insert disguised as a range insert in all its variants
// o exception effects
template<typename _Tp>
void
modifiers1()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
typedef typename list_type::value_type value_type;
list_type list0301;
value_type::reset();
// fill insert at beginning of list / empty list
list0301.insert(list0301.begin(), 3, value_type(11)); // should be [11 11 11]
VERIFY(list0301.size() == 3);
VERIFY(value_type::copyCount() == 3);
// save iterators to verify post-insert validity
iterator b = list0301.begin();
iterator m = list0301.end(); --m;
iterator e = list0301.end();
// fill insert at end of list
value_type::reset();
list0301.insert(list0301.end(), 3, value_type(13)); // should be [11 11 11 13 13 13]
VERIFY(list0301.size() == 6);
VERIFY(value_type::copyCount() == 3);
VERIFY(b == list0301.begin() && b->id() == 11);
VERIFY(e == list0301.end());
VERIFY(m->id() == 11);
// fill insert in the middle of list
++m;
value_type::reset();
list0301.insert(m, 3, value_type(12)); // should be [11 11 11 12 12 12 13 13 13]
VERIFY(list0301.size() == 9);
VERIFY(value_type::copyCount() == 3);
VERIFY(b == list0301.begin() && b->id() == 11);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
// single erase
value_type::reset();
m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
VERIFY(list0301.size() == 8);
VERIFY(value_type::dtorCount() == 1);
VERIFY(b == list0301.begin() && b->id() == 11);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
// range erase
value_type::reset();
m = list0301.erase(list0301.begin(), m); // should be [13 13]
VERIFY(list0301.size() == 2);
VERIFY(value_type::dtorCount() == 6);
VERIFY(m->id() == 13);
// range fill at beginning
const int A[] = {321, 322, 333};
const int N = sizeof(A) / sizeof(int);
value_type::reset();
b = list0301.begin();
list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
VERIFY(list0301.size() == 5);
VERIFY(value_type::copyCount() == 3);
VERIFY(m->id() == 13);
// range fill at end
value_type::reset();
list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
VERIFY(list0301.size() == 8);
VERIFY(value_type::copyCount() == 3);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
// range fill in middle
value_type::reset();
list0301.insert(m, A, A + N);
VERIFY(list0301.size() == 11);
VERIFY(value_type::copyCount() == 3);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
value_type::reset();
list0301.clear();
VERIFY(list0301.size() == 0);
VERIFY(value_type::dtorCount() == 11);
VERIFY(e == list0301.end());
}
int main()
{

View File

@ -0,0 +1,113 @@
// Copyright (C) 2001, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include <testsuite_hooks.h>
// range and fill insert/erase + clear
// missing: o fill insert disguised as a range insert in all its variants
// o exception effects
template<typename _Tp>
void
modifiers1()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
typedef typename list_type::value_type value_type;
list_type list0301;
value_type::reset();
// fill insert at beginning of list / empty list
list0301.insert(list0301.begin(), 3, value_type(11)); // should be [11 11 11]
VERIFY(list0301.size() == 3);
VERIFY(value_type::copyCount() == 3);
// save iterators to verify post-insert validity
iterator b = list0301.begin();
iterator m = list0301.end(); --m;
iterator e = list0301.end();
// fill insert at end of list
value_type::reset();
list0301.insert(list0301.end(), 3, value_type(13)); // should be [11 11 11 13 13 13]
VERIFY(list0301.size() == 6);
VERIFY(value_type::copyCount() == 3);
VERIFY(b == list0301.begin() && b->id() == 11);
VERIFY(e == list0301.end());
VERIFY(m->id() == 11);
// fill insert in the middle of list
++m;
value_type::reset();
list0301.insert(m, 3, value_type(12)); // should be [11 11 11 12 12 12 13 13 13]
VERIFY(list0301.size() == 9);
VERIFY(value_type::copyCount() == 3);
VERIFY(b == list0301.begin() && b->id() == 11);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
// single erase
value_type::reset();
m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
VERIFY(list0301.size() == 8);
VERIFY(value_type::dtorCount() == 1);
VERIFY(b == list0301.begin() && b->id() == 11);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
// range erase
value_type::reset();
m = list0301.erase(list0301.begin(), m); // should be [13 13]
VERIFY(list0301.size() == 2);
VERIFY(value_type::dtorCount() == 6);
VERIFY(m->id() == 13);
// range fill at beginning
const int A[] = {321, 322, 333};
const int N = sizeof(A) / sizeof(int);
value_type::reset();
b = list0301.begin();
list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
VERIFY(list0301.size() == 5);
VERIFY(value_type::copyCount() == 3);
VERIFY(m->id() == 13);
// range fill at end
value_type::reset();
list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
VERIFY(list0301.size() == 8);
VERIFY(value_type::copyCount() == 3);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
// range fill in middle
value_type::reset();
list0301.insert(m, A, A + N);
VERIFY(list0301.size() == 11);
VERIFY(value_type::copyCount() == 3);
VERIFY(e == list0301.end());
VERIFY(m->id() == 13);
value_type::reset();
list0301.clear();
VERIFY(list0301.size() == 0);
VERIFY(value_type::dtorCount() == 11);
VERIFY(e == list0301.end());
}

View File

@ -15,76 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include "2.h"
#include <list>
#include <testsuite_hooks.h>
// general single insert/erase + swap
template<typename _Tp>
void
modifiers2()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::value_type value_type;
typedef typename list_type::iterator iterator;
typedef typename list_type::const_iterator const_iterator;
list_type list0201;
value_type::reset();
list0201.insert(list0201.begin(), value_type(1)); // list should be [1]
VERIFY(list0201.size() == 1);
VERIFY(value_type::copyCount() == 1);
list0201.insert(list0201.end(), value_type(2)); // list should be [1 2]
VERIFY(list0201.size() == 2);
VERIFY(value_type::copyCount() == 2);
iterator i = list0201.begin();
const_iterator j = i;
VERIFY(i->id() == 1); ++i;
VERIFY(i->id() == 2);
list0201.insert(i, value_type(3)); // list should be [1 3 2]
VERIFY(list0201.size() == 3);
VERIFY(value_type::copyCount() == 3);
const_iterator k = i;
VERIFY(i->id() == 2); --i;
VERIFY(i->id() == 3); --i;
VERIFY(i->id() == 1);
VERIFY(j->id() == 1);
++i; // will point to '3'
value_type::reset();
list0201.erase(i); // should be [1 2]
VERIFY(list0201.size() == 2);
VERIFY(value_type::dtorCount() == 1);
VERIFY(k->id() == 2);
VERIFY(j->id() == 1);
list_type list0202;
value_type::reset();
VERIFY(list0202.size() == 0);
VERIFY(value_type::copyCount() == 0);
VERIFY(value_type::dtorCount() == 0);
// member swap
list0202.swap(list0201);
VERIFY(list0201.size() == 0);
VERIFY(list0202.size() == 2);
VERIFY(value_type::copyCount() == 0);
VERIFY(value_type::dtorCount() == 0);
// specialized swap
swap(list0201, list0202);
VERIFY(list0201.size() == 2);
VERIFY(list0202.size() == 0);
VERIFY(value_type::copyCount() == 0);
VERIFY(value_type::dtorCount() == 0);
}
int main()
{

View File

@ -0,0 +1,86 @@
// Copyright (C) 2001, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include <testsuite_hooks.h>
// general single insert/erase + swap
template<typename _Tp>
void
modifiers2()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::value_type value_type;
typedef typename list_type::iterator iterator;
typedef typename list_type::const_iterator const_iterator;
list_type list0201;
value_type::reset();
list0201.insert(list0201.begin(), value_type(1)); // list should be [1]
VERIFY(list0201.size() == 1);
VERIFY(value_type::copyCount() == 1);
list0201.insert(list0201.end(), value_type(2)); // list should be [1 2]
VERIFY(list0201.size() == 2);
VERIFY(value_type::copyCount() == 2);
iterator i = list0201.begin();
const_iterator j = i;
VERIFY(i->id() == 1); ++i;
VERIFY(i->id() == 2);
list0201.insert(i, value_type(3)); // list should be [1 3 2]
VERIFY(list0201.size() == 3);
VERIFY(value_type::copyCount() == 3);
const_iterator k = i;
VERIFY(i->id() == 2); --i;
VERIFY(i->id() == 3); --i;
VERIFY(i->id() == 1);
VERIFY(j->id() == 1);
++i; // will point to '3'
value_type::reset();
list0201.erase(i); // should be [1 2]
VERIFY(list0201.size() == 2);
VERIFY(value_type::dtorCount() == 1);
VERIFY(k->id() == 2);
VERIFY(j->id() == 1);
list_type list0202;
value_type::reset();
VERIFY(list0202.size() == 0);
VERIFY(value_type::copyCount() == 0);
VERIFY(value_type::dtorCount() == 0);
// member swap
list0202.swap(list0201);
VERIFY(list0201.size() == 0);
VERIFY(list0202.size() == 2);
VERIFY(value_type::copyCount() == 0);
VERIFY(value_type::dtorCount() == 0);
// specialized swap
swap(list0201, list0202);
VERIFY(list0201.size() == 2);
VERIFY(list0202.size() == 0);
VERIFY(value_type::copyCount() == 0);
VERIFY(value_type::dtorCount() == 0);
}

View File

@ -15,108 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include "3.h"
#include <list>
#include <testsuite_hooks.h>
// This test verifies the following.
//
// 23.2.2.3 void push_front(const T& x)
// 23.2.2.3 void push_back(const T& x)
// 23.2.2.3 (1) iterator and reference non-invalidation
// 23.2.2.3 (1) exception effects
// 23.2.2.3 (2) complexity requirements
//
// 23.2.2.3 void pop_front()
// 23.2.2.3 void pop_back()
// 23.2.2.3 (3) iterator and reference non-invalidation
// 23.2.2.3 (5) complexity requirements
//
// 23.2.2 const_iterator begin() const
// 23.2.2 iterator end()
// 23.2.2 const_reverse_iterator rbegin() const
// 23.2.2 _reference front()
// 23.2.2 const_reference front() const
// 23.2.2 reference back()
// 23.2.2 const_reference back() const
//
template<typename _Tp>
void
modifiers3()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
typedef typename list_type::value_type value_type;
typedef typename list_type::const_iterator const_iterator;
typedef typename list_type::const_reverse_iterator const_reverse_iterator;
list_type list0101;
const_iterator i;
const_reverse_iterator j;
iterator k;
value_type::reset();
list0101.push_back(value_type(1)); // list should be [1]
VERIFY(list0101.size() == 1);
VERIFY(value_type::copyCount() == 1);
k = list0101.end();
--k;
VERIFY(k->id() == 1);
VERIFY(k->id() == list0101.front().id());
VERIFY(k->id() == list0101.back().id());
list0101.push_front(value_type(2)); // list should be [2 1]
VERIFY(list0101.size() == 2);
VERIFY(value_type::copyCount() == 2);
VERIFY(k->id() == 1);
list0101.push_back(value_type(3)); // list should be [2 1 3]
VERIFY(list0101.size() == 3);
VERIFY(value_type::copyCount() == 3);
VERIFY(k->id() == 1);
try
{
list0101.push_back(value_type(4, true));
VERIFY(false);
}
catch (...)
{
VERIFY(list0101.size() == 3);
VERIFY(value_type::copyCount() == 4);
}
i = list0101.begin();
VERIFY(i->id() == 2);
VERIFY(i->id() == list0101.front().id());
j = list0101.rbegin();
VERIFY(j->id() == 3);
VERIFY(j->id() == list0101.back().id());
++i;
VERIFY(i->id() == 1);
++j;
VERIFY(j->id() == 1);
value_type::reset();
list0101.pop_back(); // list should be [2 1]
VERIFY(list0101.size() == 2);
VERIFY(value_type::dtorCount() == 1);
VERIFY(i->id() == 1);
VERIFY(k->id() == 1);
list0101.pop_front(); // list should be [1]
VERIFY(list0101.size() == 1);
VERIFY(value_type::dtorCount() == 2);
VERIFY(i->id() == 1);
VERIFY(k->id() == 1);
}
int main()
{

View File

@ -0,0 +1,118 @@
// Copyright (C) 2001, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include <testsuite_hooks.h>
// This test verifies the following.
//
// 23.2.2.3 void push_front(const T& x)
// 23.2.2.3 void push_back(const T& x)
// 23.2.2.3 (1) iterator and reference non-invalidation
// 23.2.2.3 (1) exception effects
// 23.2.2.3 (2) complexity requirements
//
// 23.2.2.3 void pop_front()
// 23.2.2.3 void pop_back()
// 23.2.2.3 (3) iterator and reference non-invalidation
// 23.2.2.3 (5) complexity requirements
//
// 23.2.2 const_iterator begin() const
// 23.2.2 iterator end()
// 23.2.2 const_reverse_iterator rbegin() const
// 23.2.2 _reference front()
// 23.2.2 const_reference front() const
// 23.2.2 reference back()
// 23.2.2 const_reference back() const
//
template<typename _Tp>
void
modifiers3()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
typedef typename list_type::value_type value_type;
typedef typename list_type::const_iterator const_iterator;
typedef typename list_type::const_reverse_iterator const_reverse_iterator;
list_type list0101;
const_iterator i;
const_reverse_iterator j;
iterator k;
value_type::reset();
list0101.push_back(value_type(1)); // list should be [1]
VERIFY(list0101.size() == 1);
VERIFY(value_type::copyCount() == 1);
k = list0101.end();
--k;
VERIFY(k->id() == 1);
VERIFY(k->id() == list0101.front().id());
VERIFY(k->id() == list0101.back().id());
list0101.push_front(value_type(2)); // list should be [2 1]
VERIFY(list0101.size() == 2);
VERIFY(value_type::copyCount() == 2);
VERIFY(k->id() == 1);
list0101.push_back(value_type(3)); // list should be [2 1 3]
VERIFY(list0101.size() == 3);
VERIFY(value_type::copyCount() == 3);
VERIFY(k->id() == 1);
try
{
list0101.push_back(value_type(4, true));
VERIFY(false);
}
catch (...)
{
VERIFY(list0101.size() == 3);
VERIFY(value_type::copyCount() == 4);
}
i = list0101.begin();
VERIFY(i->id() == 2);
VERIFY(i->id() == list0101.front().id());
j = list0101.rbegin();
VERIFY(j->id() == 3);
VERIFY(j->id() == list0101.back().id());
++i;
VERIFY(i->id() == 1);
++j;
VERIFY(j->id() == 1);
value_type::reset();
list0101.pop_back(); // list should be [2 1]
VERIFY(list0101.size() == 2);
VERIFY(value_type::dtorCount() == 1);
VERIFY(i->id() == 1);
VERIFY(k->id() == 1);
list0101.pop_front(); // list should be [1]
VERIFY(list0101.size() == 1);
VERIFY(value_type::dtorCount() == 2);
VERIFY(i->id() == 1);
VERIFY(k->id() == 1);
}

View File

@ -1,3 +1,5 @@
// { dg-require-time "" }
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -15,82 +17,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
// { dg-require-time "" }
#include "25288.h"
#include <list>
#include <testsuite_hooks.h>
#include <ext/throw_allocator.h>
// libstdc++/25288
template<typename _Tp>
void insert1()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename _Tp::value_type value_type;
typedef typename _Tp::allocator_type allocator_type;
typedef typename _Tp::size_type size_type;
for (int j = 0; j < 10; ++j)
for (int i = 0; i < 10; ++i)
{
allocator_type alloc1;
typename allocator_type::never_adjustor adjust1;
list_type list1(alloc1);
for (int k = 0; k < j; ++k)
list1.push_back(value_type(-(k + 1)));
try
{
typename allocator_type::always_adjustor adjust2;
list1.insert(list1.begin(), 10, 99);
VERIFY( false );
}
catch (__gnu_cxx::forced_exception_error&)
{
VERIFY( true );
}
catch (...)
{
__throw_exception_again;
}
VERIFY( list1.size() == size_type(j) );
VERIFY( list1.size() == 0 || list1.back() == -j );
VERIFY( list1.size() == 0 || list1.front() == -1 );
allocator_type alloc2;
list_type list2(alloc2);
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int k = 0; k < j; ++k)
list2.push_back(-(k + 1));
try
{
typename allocator_type::always_adjustor adjust3;
list2.insert(list2.begin(), data, data + 10);
VERIFY( false );
}
catch (__gnu_cxx::forced_exception_error&)
{
VERIFY( true );
}
catch (...)
{
VERIFY( false );
}
VERIFY( list2.size() == size_type(j) );
VERIFY( list2.size() == 0 || list2.back() == -j );
VERIFY( list2.size() == 0 || list2.front() == -1 );
}
}
int main()
{

View File

@ -0,0 +1,90 @@
// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list modifiers [lib.list.modifiers]
#include <testsuite_hooks.h>
#include <ext/throw_allocator.h>
// libstdc++/25288
template<typename _Tp>
void insert1()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename _Tp::value_type value_type;
typedef typename _Tp::allocator_type allocator_type;
typedef typename _Tp::size_type size_type;
for (int j = 0; j < 10; ++j)
for (int i = 0; i < 10; ++i)
{
allocator_type alloc1;
typename allocator_type::never_adjustor adjust1;
list_type list1(alloc1);
for (int k = 0; k < j; ++k)
list1.push_back(value_type(-(k + 1)));
try
{
typename allocator_type::always_adjustor adjust2;
list1.insert(list1.begin(), 10, 99);
VERIFY( false );
}
catch (__gnu_cxx::forced_exception_error&)
{
VERIFY( true );
}
catch (...)
{
__throw_exception_again;
}
VERIFY( list1.size() == size_type(j) );
VERIFY( list1.size() == 0 || list1.back() == -j );
VERIFY( list1.size() == 0 || list1.front() == -1 );
allocator_type alloc2;
list_type list2(alloc2);
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int k = 0; k < j; ++k)
list2.push_back(-(k + 1));
try
{
typename allocator_type::always_adjustor adjust3;
list2.insert(list2.begin(), data, data + 10);
VERIFY( false );
}
catch (__gnu_cxx::forced_exception_error&)
{
VERIFY( true );
}
catch (...)
{
VERIFY( false );
}
VERIFY( list2.size() == size_type(j) );
VERIFY( list2.size() == 0 || list2.back() == -j );
VERIFY( list2.size() == 0 || list2.front() == -1 );
}
}

View File

@ -15,12 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include "1.h"
#include <list>
#include <testsuite_hooks.h>
struct T { int i; };
int swap_calls;
namespace std
{
@ -30,41 +26,6 @@ namespace std
{ ++swap_calls; }
}
// Should use list specialization for swap.
template<typename _Tp>
void
swap11()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type A;
list_type B;
swap_calls = 0;
std::swap(A, B);
VERIFY(1 == swap_calls);
}
// Should use list specialization for swap.
template<typename _Tp>
void
swap12()
{
using namespace std;
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type A;
list_type B;
swap_calls = 0;
swap(A, B);
VERIFY(1 == swap_calls);
}
#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
template class __gnu_cxx::__mt_alloc<std::_List_node<T> >;
#endif
// See c++/13658 for background info.
int main()
{

View File

@ -0,0 +1,58 @@
// Copyright (C) 2004, 2009 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <algorithm>
#include <testsuite_hooks.h>
struct T { int i; };
int swap_calls;
// Should use list specialization for swap.
template<typename _Tp>
void
swap11()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type A;
list_type B;
swap_calls = 0;
std::swap(A, B);
VERIFY(1 == swap_calls);
}
// Should use list specialization for swap.
template<typename _Tp>
void
swap12()
{
using namespace std;
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type A;
list_type B;
swap_calls = 0;
swap(A, B);
VERIFY(1 == swap_calls);
}
#if !__GXX_WEAK__ && _MT_ALLOCATOR_H
template class __gnu_cxx::__mt_alloc<std::_List_node<T> >;
#endif

View File

@ -17,115 +17,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list::swap
#include "2.h"
#include <list>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// uneq_allocator as a non-empty allocator.
template<typename _Tp>
void
swap2()
{
bool test __attribute__((unused)) = true;
using namespace std;
typedef _Tp list_type;
typedef typename list_type::allocator_type allocator_type;
typedef typename list_type::size_type size_type;
const char title01[] = "Rivers of sand";
const char title02[] = "Concret PH";
const char title03[] = "Sonatas and Interludes for Prepared Piano";
const char title04[] = "never as tired as when i'm waking up";
const size_t N1 = sizeof(title01);
const size_t N2 = sizeof(title02);
const size_t N3 = sizeof(title03);
const size_t N4 = sizeof(title04);
size_type size01, size02;
allocator_type alloc01(1);
list_type lis01(alloc01);
size01 = lis01.size();
list_type lis02(alloc01);
size02 = lis02.size();
lis01.swap(lis02);
VERIFY( lis01.size() == size02 );
VERIFY( lis01.empty() );
VERIFY( lis02.size() == size01 );
VERIFY( lis02.empty() );
list_type lis03(alloc01);
size01 = lis03.size();
list_type lis04(title02, title02 + N2, alloc01);
size02 = lis04.size();
lis03.swap(lis04);
VERIFY( lis03.size() == size02 );
VERIFY( equal(lis03.begin(), lis03.end(), title02) );
VERIFY( lis04.size() == size01 );
VERIFY( lis04.empty() );
list_type lis05(title01, title01 + N1, alloc01);
size01 = lis05.size();
list_type lis06(title02, title02 + N2, alloc01);
size02 = lis06.size();
lis05.swap(lis06);
VERIFY( lis05.size() == size02 );
VERIFY( equal(lis05.begin(), lis05.end(), title02) );
VERIFY( lis06.size() == size01 );
VERIFY( equal(lis06.begin(), lis06.end(), title01) );
list_type lis07(title01, title01 + N1, alloc01);
size01 = lis07.size();
list_type lis08(title03, title03 + N3, alloc01);
size02 = lis08.size();
lis07.swap(lis08);
VERIFY( lis07.size() == size02 );
VERIFY( equal(lis07.begin(), lis07.end(), title03) );
VERIFY( lis08.size() == size01 );
VERIFY( equal(lis08.begin(), lis08.end(), title01) );
list_type lis09(title03, title03 + N3, alloc01);
size01 = lis09.size();
list_type lis10(title04, title04 + N4, alloc01);
size02 = lis10.size();
lis09.swap(lis10);
VERIFY( lis09.size() == size02 );
VERIFY( equal(lis09.begin(), lis09.end(), title04) );
VERIFY( lis10.size() == size01 );
VERIFY( equal(lis10.begin(), lis10.end(), title03) );
list_type lis11(title04, title04 + N4, alloc01);
size01 = lis11.size();
list_type lis12(title01, title01 + N1, alloc01);
size02 = lis12.size();
lis11.swap(lis12);
VERIFY( lis11.size() == size02 );
VERIFY( equal(lis11.begin(), lis11.end(), title01) );
VERIFY( lis12.size() == size01 );
VERIFY( equal(lis12.begin(), lis12.end(), title04) );
list_type lis13(title03, title03 + N3, alloc01);
size01 = lis13.size();
list_type lis14(title03, title03 + N3, alloc01);
size02 = lis14.size();
lis13.swap(lis14);
VERIFY( lis13.size() == size02 );
VERIFY( equal(lis13.begin(), lis13.end(), title03) );
VERIFY( lis14.size() == size01 );
VERIFY( equal(lis14.begin(), lis14.end(), title03) );
}
int main()
{

View File

@ -0,0 +1,127 @@
// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list::swap
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// uneq_allocator as a non-empty allocator.
template<typename _Tp>
void
swap2()
{
bool test __attribute__((unused)) = true;
using namespace std;
typedef _Tp list_type;
typedef typename list_type::allocator_type allocator_type;
typedef typename list_type::size_type size_type;
const char title01[] = "Rivers of sand";
const char title02[] = "Concret PH";
const char title03[] = "Sonatas and Interludes for Prepared Piano";
const char title04[] = "never as tired as when i'm waking up";
const size_t N1 = sizeof(title01);
const size_t N2 = sizeof(title02);
const size_t N3 = sizeof(title03);
const size_t N4 = sizeof(title04);
size_type size01, size02;
allocator_type alloc01(1);
list_type lis01(alloc01);
size01 = lis01.size();
list_type lis02(alloc01);
size02 = lis02.size();
lis01.swap(lis02);
VERIFY( lis01.size() == size02 );
VERIFY( lis01.empty() );
VERIFY( lis02.size() == size01 );
VERIFY( lis02.empty() );
list_type lis03(alloc01);
size01 = lis03.size();
list_type lis04(title02, title02 + N2, alloc01);
size02 = lis04.size();
lis03.swap(lis04);
VERIFY( lis03.size() == size02 );
VERIFY( equal(lis03.begin(), lis03.end(), title02) );
VERIFY( lis04.size() == size01 );
VERIFY( lis04.empty() );
list_type lis05(title01, title01 + N1, alloc01);
size01 = lis05.size();
list_type lis06(title02, title02 + N2, alloc01);
size02 = lis06.size();
lis05.swap(lis06);
VERIFY( lis05.size() == size02 );
VERIFY( equal(lis05.begin(), lis05.end(), title02) );
VERIFY( lis06.size() == size01 );
VERIFY( equal(lis06.begin(), lis06.end(), title01) );
list_type lis07(title01, title01 + N1, alloc01);
size01 = lis07.size();
list_type lis08(title03, title03 + N3, alloc01);
size02 = lis08.size();
lis07.swap(lis08);
VERIFY( lis07.size() == size02 );
VERIFY( equal(lis07.begin(), lis07.end(), title03) );
VERIFY( lis08.size() == size01 );
VERIFY( equal(lis08.begin(), lis08.end(), title01) );
list_type lis09(title03, title03 + N3, alloc01);
size01 = lis09.size();
list_type lis10(title04, title04 + N4, alloc01);
size02 = lis10.size();
lis09.swap(lis10);
VERIFY( lis09.size() == size02 );
VERIFY( equal(lis09.begin(), lis09.end(), title04) );
VERIFY( lis10.size() == size01 );
VERIFY( equal(lis10.begin(), lis10.end(), title03) );
list_type lis11(title04, title04 + N4, alloc01);
size01 = lis11.size();
list_type lis12(title01, title01 + N1, alloc01);
size02 = lis12.size();
lis11.swap(lis12);
VERIFY( lis11.size() == size02 );
VERIFY( equal(lis11.begin(), lis11.end(), title01) );
VERIFY( lis12.size() == size01 );
VERIFY( equal(lis12.begin(), lis12.end(), title04) );
list_type lis13(title03, title03 + N3, alloc01);
size01 = lis13.size();
list_type lis14(title03, title03 + N3, alloc01);
size02 = lis14.size();
lis13.swap(lis14);
VERIFY( lis13.size() == size02 );
VERIFY( equal(lis13.begin(), lis13.end(), title03) );
VERIFY( lis14.size() == size01 );
VERIFY( equal(lis14.begin(), lis14.end(), title03) );
}

View File

@ -17,144 +17,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list::swap
#include "3.h"
#include <list>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// uneq_allocator, two different personalities.
template<typename _Tp>
void
swap3()
{
bool test __attribute__((unused)) = true;
using namespace std;
typedef _Tp list_type;
typedef typename list_type::allocator_type allocator_type;
typedef typename list_type::size_type size_type;
const char title01[] = "Rivers of sand";
const char title02[] = "Concret PH";
const char title03[] = "Sonatas and Interludes for Prepared Piano";
const char title04[] = "never as tired as when i'm waking up";
const size_t N1 = sizeof(title01);
const size_t N2 = sizeof(title02);
const size_t N3 = sizeof(title03);
const size_t N4 = sizeof(title04);
size_type size01, size02;
allocator_type alloc01(1), alloc02(2);
int personality01, personality02;
list_type lis01(alloc01);
size01 = lis01.size();
personality01 = lis01.get_allocator().get_personality();
list_type lis02(alloc02);
size02 = lis02.size();
personality02 = lis02.get_allocator().get_personality();
lis01.swap(lis02);
VERIFY( lis01.size() == size02 );
VERIFY( lis01.empty() );
VERIFY( lis02.size() == size01 );
VERIFY( lis02.empty() );
VERIFY( lis01.get_allocator().get_personality() == personality02 );
VERIFY( lis02.get_allocator().get_personality() == personality01 );
list_type lis03(alloc02);
size01 = lis03.size();
personality01 = lis03.get_allocator().get_personality();
list_type lis04(title02, title02 + N2, alloc01);
size02 = lis04.size();
personality02 = lis04.get_allocator().get_personality();
lis03.swap(lis04);
VERIFY( lis03.size() == size02 );
VERIFY( equal(lis03.begin(), lis03.end(), title02) );
VERIFY( lis04.size() == size01 );
VERIFY( lis04.empty() );
VERIFY( lis03.get_allocator().get_personality() == personality02 );
VERIFY( lis04.get_allocator().get_personality() == personality01 );
list_type lis05(title01, title01 + N1, alloc01);
size01 = lis05.size();
personality01 = lis05.get_allocator().get_personality();
list_type lis06(title02, title02 + N2, alloc02);
size02 = lis06.size();
personality02 = lis06.get_allocator().get_personality();
lis05.swap(lis06);
VERIFY( lis05.size() == size02 );
VERIFY( equal(lis05.begin(), lis05.end(), title02) );
VERIFY( lis06.size() == size01 );
VERIFY( equal(lis06.begin(), lis06.end(), title01) );
VERIFY( lis05.get_allocator().get_personality() == personality02 );
VERIFY( lis06.get_allocator().get_personality() == personality01 );
list_type lis07(title01, title01 + N1, alloc02);
size01 = lis07.size();
personality01 = lis07.get_allocator().get_personality();
list_type lis08(title03, title03 + N3, alloc01);
size02 = lis08.size();
personality02 = lis08.get_allocator().get_personality();
lis07.swap(lis08);
VERIFY( lis07.size() == size02 );
VERIFY( equal(lis07.begin(), lis07.end(), title03) );
VERIFY( lis08.size() == size01 );
VERIFY( equal(lis08.begin(), lis08.end(), title01) );
VERIFY( lis07.get_allocator().get_personality() == personality02 );
VERIFY( lis08.get_allocator().get_personality() == personality01 );
list_type lis09(title03, title03 + N3, alloc01);
size01 = lis09.size();
personality01 = lis09.get_allocator().get_personality();
list_type lis10(title04, title04 + N4, alloc02);
size02 = lis10.size();
personality02 = lis10.get_allocator().get_personality();
lis09.swap(lis10);
VERIFY( lis09.size() == size02 );
VERIFY( equal(lis09.begin(), lis09.end(), title04) );
VERIFY( lis10.size() == size01 );
VERIFY( equal(lis10.begin(), lis10.end(), title03) );
VERIFY( lis09.get_allocator().get_personality() == personality02 );
VERIFY( lis10.get_allocator().get_personality() == personality01 );
list_type lis11(title04, title04 + N4, alloc02);
size01 = lis11.size();
personality01 = lis11.get_allocator().get_personality();
list_type lis12(title01, title01 + N1, alloc01);
size02 = lis12.size();
personality02 = lis12.get_allocator().get_personality();
lis11.swap(lis12);
VERIFY( lis11.size() == size02 );
VERIFY( equal(lis11.begin(), lis11.end(), title01) );
VERIFY( lis12.size() == size01 );
VERIFY( equal(lis12.begin(), lis12.end(), title04) );
VERIFY( lis11.get_allocator().get_personality() == personality02 );
VERIFY( lis12.get_allocator().get_personality() == personality01 );
list_type lis13(title03, title03 + N3, alloc01);
size01 = lis13.size();
personality01 = lis13.get_allocator().get_personality();
list_type lis14(title03, title03 + N3, alloc02);
size02 = lis14.size();
personality02 = lis14.get_allocator().get_personality();
lis13.swap(lis14);
VERIFY( lis13.size() == size02 );
VERIFY( equal(lis13.begin(), lis13.end(), title03) );
VERIFY( lis14.size() == size01 );
VERIFY( equal(lis14.begin(), lis14.end(), title03) );
VERIFY( lis13.get_allocator().get_personality() == personality02 );
VERIFY( lis14.get_allocator().get_personality() == personality01 );
}
int main()
{

View File

@ -0,0 +1,156 @@
// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.3 list::swap
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// uneq_allocator, two different personalities.
template<typename _Tp>
void
swap3()
{
bool test __attribute__((unused)) = true;
using namespace std;
typedef _Tp list_type;
typedef typename list_type::allocator_type allocator_type;
typedef typename list_type::size_type size_type;
const char title01[] = "Rivers of sand";
const char title02[] = "Concret PH";
const char title03[] = "Sonatas and Interludes for Prepared Piano";
const char title04[] = "never as tired as when i'm waking up";
const size_t N1 = sizeof(title01);
const size_t N2 = sizeof(title02);
const size_t N3 = sizeof(title03);
const size_t N4 = sizeof(title04);
size_type size01, size02;
allocator_type alloc01(1), alloc02(2);
int personality01, personality02;
list_type lis01(alloc01);
size01 = lis01.size();
personality01 = lis01.get_allocator().get_personality();
list_type lis02(alloc02);
size02 = lis02.size();
personality02 = lis02.get_allocator().get_personality();
lis01.swap(lis02);
VERIFY( lis01.size() == size02 );
VERIFY( lis01.empty() );
VERIFY( lis02.size() == size01 );
VERIFY( lis02.empty() );
VERIFY( lis01.get_allocator().get_personality() == personality02 );
VERIFY( lis02.get_allocator().get_personality() == personality01 );
list_type lis03(alloc02);
size01 = lis03.size();
personality01 = lis03.get_allocator().get_personality();
list_type lis04(title02, title02 + N2, alloc01);
size02 = lis04.size();
personality02 = lis04.get_allocator().get_personality();
lis03.swap(lis04);
VERIFY( lis03.size() == size02 );
VERIFY( equal(lis03.begin(), lis03.end(), title02) );
VERIFY( lis04.size() == size01 );
VERIFY( lis04.empty() );
VERIFY( lis03.get_allocator().get_personality() == personality02 );
VERIFY( lis04.get_allocator().get_personality() == personality01 );
list_type lis05(title01, title01 + N1, alloc01);
size01 = lis05.size();
personality01 = lis05.get_allocator().get_personality();
list_type lis06(title02, title02 + N2, alloc02);
size02 = lis06.size();
personality02 = lis06.get_allocator().get_personality();
lis05.swap(lis06);
VERIFY( lis05.size() == size02 );
VERIFY( equal(lis05.begin(), lis05.end(), title02) );
VERIFY( lis06.size() == size01 );
VERIFY( equal(lis06.begin(), lis06.end(), title01) );
VERIFY( lis05.get_allocator().get_personality() == personality02 );
VERIFY( lis06.get_allocator().get_personality() == personality01 );
list_type lis07(title01, title01 + N1, alloc02);
size01 = lis07.size();
personality01 = lis07.get_allocator().get_personality();
list_type lis08(title03, title03 + N3, alloc01);
size02 = lis08.size();
personality02 = lis08.get_allocator().get_personality();
lis07.swap(lis08);
VERIFY( lis07.size() == size02 );
VERIFY( equal(lis07.begin(), lis07.end(), title03) );
VERIFY( lis08.size() == size01 );
VERIFY( equal(lis08.begin(), lis08.end(), title01) );
VERIFY( lis07.get_allocator().get_personality() == personality02 );
VERIFY( lis08.get_allocator().get_personality() == personality01 );
list_type lis09(title03, title03 + N3, alloc01);
size01 = lis09.size();
personality01 = lis09.get_allocator().get_personality();
list_type lis10(title04, title04 + N4, alloc02);
size02 = lis10.size();
personality02 = lis10.get_allocator().get_personality();
lis09.swap(lis10);
VERIFY( lis09.size() == size02 );
VERIFY( equal(lis09.begin(), lis09.end(), title04) );
VERIFY( lis10.size() == size01 );
VERIFY( equal(lis10.begin(), lis10.end(), title03) );
VERIFY( lis09.get_allocator().get_personality() == personality02 );
VERIFY( lis10.get_allocator().get_personality() == personality01 );
list_type lis11(title04, title04 + N4, alloc02);
size01 = lis11.size();
personality01 = lis11.get_allocator().get_personality();
list_type lis12(title01, title01 + N1, alloc01);
size02 = lis12.size();
personality02 = lis12.get_allocator().get_personality();
lis11.swap(lis12);
VERIFY( lis11.size() == size02 );
VERIFY( equal(lis11.begin(), lis11.end(), title01) );
VERIFY( lis12.size() == size01 );
VERIFY( equal(lis12.begin(), lis12.end(), title04) );
VERIFY( lis11.get_allocator().get_personality() == personality02 );
VERIFY( lis12.get_allocator().get_personality() == personality01 );
list_type lis13(title03, title03 + N3, alloc01);
size01 = lis13.size();
personality01 = lis13.get_allocator().get_personality();
list_type lis14(title03, title03 + N3, alloc02);
size02 = lis14.size();
personality02 = lis14.get_allocator().get_personality();
lis13.swap(lis14);
VERIFY( lis13.size() == size02 );
VERIFY( equal(lis13.begin(), lis13.end(), title03) );
VERIFY( lis14.size() == size01 );
VERIFY( equal(lis14.begin(), lis14.end(), title03) );
VERIFY( lis13.get_allocator().get_personality() == personality02 );
VERIFY( lis14.get_allocator().get_personality() == personality01 );
}

View File

@ -17,31 +17,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 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 "moveable.h"
#include <list>
#include <utility>
#include <testsuite_hooks.h>
template<typename _Tp>
void
test_moveable()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type a,b;
a.push_back(1);
b = std::move(a);
VERIFY( b.size() == 1 && *b.begin() == 1 && a.size() == 0 );
list_type c(std::move(b));
VERIFY( c.size() == 1 && *c.begin() == 1 );
VERIFY( b.size() == 0 );
}
int main()
{

View File

@ -0,0 +1,41 @@
// Copyright (C) 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 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 <utility>
#include <testsuite_hooks.h>
template<typename _Tp>
void
test_moveable()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
list_type a,b;
a.push_back(1);
b = std::move(a);
VERIFY( b.size() == 1 && *b.begin() == 1 && a.size() == 0 );
list_type c(std::move(b));
VERIFY( c.size() == 1 && *c.begin() == 1 );
VERIFY( b.size() == 0 );
}

View File

@ -15,58 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include "1.h"
#include <list>
#include <testsuite_hooks.h>
// splice(p, x) + remove + reverse
template<typename _Tp>
void
operations01()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int K = 417;
const int A[] = {1, 2, 3, 4, 5};
const int B[] = {K, K, K, K, K};
const std::size_t N = sizeof(A) / sizeof(int);
const std::size_t M = sizeof(B) / sizeof(int);
list_type list0101(A, A + N);
list_type list0102(B, B + M);
iterator p = list0101.begin();
VERIFY(list0101.size() == N);
VERIFY(list0102.size() == M);
++p;
list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
VERIFY(list0101.size() == N + M);
VERIFY(list0102.size() == 0);
// remove range from middle
list0101.remove(K);
VERIFY(list0101.size() == N);
// remove first element
list0101.remove(1);
VERIFY(list0101.size() == N - 1);
// remove last element
list0101.remove(5);
VERIFY(list0101.size() == N - 2);
// reverse
list0101.reverse();
p = list0101.begin();
VERIFY(*p == 4); ++p;
VERIFY(*p == 3); ++p;
VERIFY(*p == 2); ++p;
VERIFY(p == list0101.end());
}
int main()
{

View File

@ -0,0 +1,68 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include <testsuite_hooks.h>
// splice(p, x) + remove + reverse
template<typename _Tp>
void
operations01()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int K = 417;
const int A[] = {1, 2, 3, 4, 5};
const int B[] = {K, K, K, K, K};
const std::size_t N = sizeof(A) / sizeof(int);
const std::size_t M = sizeof(B) / sizeof(int);
list_type list0101(A, A + N);
list_type list0102(B, B + M);
iterator p = list0101.begin();
VERIFY(list0101.size() == N);
VERIFY(list0102.size() == M);
++p;
list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
VERIFY(list0101.size() == N + M);
VERIFY(list0102.size() == 0);
// remove range from middle
list0101.remove(K);
VERIFY(list0101.size() == N);
// remove first element
list0101.remove(1);
VERIFY(list0101.size() == N - 1);
// remove last element
list0101.remove(5);
VERIFY(list0101.size() == N - 2);
// reverse
list0101.reverse();
p = list0101.begin();
VERIFY(*p == 4); ++p;
VERIFY(*p == 3); ++p;
VERIFY(*p == 2); ++p;
VERIFY(p == list0101.end());
}

View File

@ -15,44 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include "2.h"
#include <list>
#include <testsuite_hooks.h>
// splice(p, x, i) + remove_if + operator==
template<typename _Tp>
void
operations02()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int A[] = {1, 2, 3, 4, 5};
const int B[] = {2, 1, 3, 4, 5};
const int C[] = {1, 3, 4, 5, 2};
const int N = sizeof(A) / sizeof(int);
list_type list0201(A, A + N);
list_type list0202(A, A + N);
list_type list0203(B, B + N);
list_type list0204(C, C + N);
iterator i = list0201.begin();
// result should be unchanged
list0201.splice(list0201.begin(), list0201, i);
VERIFY(list0201 == list0202);
// result should be [2 1 3 4 5]
++i;
list0201.splice(list0201.begin(), list0201, i);
VERIFY(list0201 != list0202);
VERIFY(list0201 == list0203);
// result should be [1 3 4 5 2]
list0201.splice(list0201.end(), list0201, i);
VERIFY(list0201 == list0204);
}
int main()
{

View File

@ -0,0 +1,54 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include <testsuite_hooks.h>
// splice(p, x, i) + remove_if + operator==
template<typename _Tp>
void
operations02()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int A[] = {1, 2, 3, 4, 5};
const int B[] = {2, 1, 3, 4, 5};
const int C[] = {1, 3, 4, 5, 2};
const int N = sizeof(A) / sizeof(int);
list_type list0201(A, A + N);
list_type list0202(A, A + N);
list_type list0203(B, B + N);
list_type list0204(C, C + N);
iterator i = list0201.begin();
// result should be unchanged
list0201.splice(list0201.begin(), list0201, i);
VERIFY(list0201 == list0202);
// result should be [2 1 3 4 5]
++i;
list0201.splice(list0201.begin(), list0201, i);
VERIFY(list0201 != list0202);
VERIFY(list0201 == list0203);
// result should be [1 3 4 5 2]
list0201.splice(list0201.end(), list0201, i);
VERIFY(list0201 == list0204);
}

View File

@ -15,58 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include "3.h"
#include <list>
#include <testsuite_hooks.h>
// splice(p, x, f, l) + sort + merge + unique
template<typename _Tp>
void
operations03()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int A[] = {103, 203, 603, 303, 403, 503};
const int B[] = {417, 417, 417, 417, 417};
const int E[] = {103, 417, 417, 203, 603, 303, 403, 503};
const int F[] = {103, 203, 303, 403, 417, 417, 503, 603};
const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603};
const int D[] = {103, 203, 303, 403, 417, 503, 603};
const int N = sizeof(A) / sizeof(int);
const int M = sizeof(B) / sizeof(int);
const int P = sizeof(C) / sizeof(int);
const int Q = sizeof(D) / sizeof(int);
const int R = sizeof(E) / sizeof(int);
list_type list0301(A, A + N);
list_type list0302(B, B + M);
list_type list0303(C, C + P);
list_type list0304(D, D + Q);
list_type list0305(E, E + R);
list_type list0306(F, F + R);
iterator p = list0301.begin();
iterator q = list0302.begin();
++p; ++q; ++q;
list0301.splice(p, list0302, list0302.begin(), q);
VERIFY(list0301 == list0305);
VERIFY(list0301.size() == N + 2);
VERIFY(list0302.size() == M - 2);
list0301.sort();
VERIFY(list0301 == list0306);
list0301.merge(list0302);
VERIFY(list0301.size() == N + M);
VERIFY(list0302.size() == 0);
VERIFY(list0301 == list0303);
list0301.unique();
VERIFY(list0301 == list0304);
}
int main(void)
{

View File

@ -0,0 +1,68 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include <testsuite_hooks.h>
// splice(p, x, f, l) + sort + merge + unique
template<typename _Tp>
void
operations03()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::iterator iterator;
const int A[] = {103, 203, 603, 303, 403, 503};
const int B[] = {417, 417, 417, 417, 417};
const int E[] = {103, 417, 417, 203, 603, 303, 403, 503};
const int F[] = {103, 203, 303, 403, 417, 417, 503, 603};
const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603};
const int D[] = {103, 203, 303, 403, 417, 503, 603};
const int N = sizeof(A) / sizeof(int);
const int M = sizeof(B) / sizeof(int);
const int P = sizeof(C) / sizeof(int);
const int Q = sizeof(D) / sizeof(int);
const int R = sizeof(E) / sizeof(int);
list_type list0301(A, A + N);
list_type list0302(B, B + M);
list_type list0303(C, C + P);
list_type list0304(D, D + Q);
list_type list0305(E, E + R);
list_type list0306(F, F + R);
iterator p = list0301.begin();
iterator q = list0302.begin();
++p; ++q; ++q;
list0301.splice(p, list0302, list0302.begin(), q);
VERIFY(list0301 == list0305);
VERIFY(list0301.size() == N + 2);
VERIFY(list0302.size() == M - 2);
list0301.sort();
VERIFY(list0301 == list0306);
list0301.merge(list0302);
VERIFY(list0301.size() == N + M);
VERIFY(list0302.size() == 0);
VERIFY(list0301 == list0303);
list0301.unique();
VERIFY(list0301 == list0304);
}

View File

@ -15,81 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include "4.h"
#include <list>
#include <testsuite_hooks.h>
// A comparison predicate to order by rightmost digit. Tracks call
// counts for performance checks.
struct CompLastLt
{
bool operator()(const int x, const int y)
{ ++itsCount; return x % 10 < y % 10; }
static int count() { return itsCount; }
static void reset() { itsCount = 0; }
static int itsCount;
};
int CompLastLt::itsCount;
struct CompLastEq
{
bool operator()(const int x, const int y)
{ ++itsCount; return x % 10 == y % 10; }
static int count() { return itsCount; }
static void reset() { itsCount = 0; }
static int itsCount;
};
int CompLastEq::itsCount;
// sort(pred) + merge(pred) + unique(pred)
// also checks performance requirements
template<typename _Tp>
void
operations04()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
const int A[] = {1, 2, 3, 4, 5, 6};
const int B[] = {12, 15, 13, 14, 11};
const int C[] = {11, 12, 13, 14, 15};
const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6};
const int N = sizeof(A) / sizeof(int);
const int M = sizeof(B) / sizeof(int);
const int Q = sizeof(D) / sizeof(int);
list_type list0401(A, A + N);
list_type list0402(B, B + M);
list_type list0403(C, C + M);
list_type list0404(D, D + Q);
list_type list0405(A, A + N);
// sort B
CompLastLt lt;
CompLastLt::reset();
list0402.sort(lt);
VERIFY(list0402 == list0403);
CompLastLt::reset();
list0401.merge(list0402, lt);
VERIFY(list0401 == list0404);
#ifndef _GLIBCXX_DEBUG
VERIFY(lt.count() <= (N + M - 1));
#endif
CompLastEq eq;
CompLastEq::reset();
list0401.unique(eq);
VERIFY(list0401 == list0405);
#ifndef _GLIBCXX_DEBUG
VERIFY(eq.count() == (N + M - 1));
#endif
}
int main()
{

View File

@ -0,0 +1,92 @@
// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include <testsuite_hooks.h>
// A comparison predicate to order by rightmost digit. Tracks call
// counts for performance checks.
struct CompLastLt
{
bool operator()(const int x, const int y)
{ ++itsCount; return x % 10 < y % 10; }
static int count() { return itsCount; }
static void reset() { itsCount = 0; }
static int itsCount;
};
int CompLastLt::itsCount;
struct CompLastEq
{
bool operator()(const int x, const int y)
{ ++itsCount; return x % 10 == y % 10; }
static int count() { return itsCount; }
static void reset() { itsCount = 0; }
static int itsCount;
};
int CompLastEq::itsCount;
// sort(pred) + merge(pred) + unique(pred)
// also checks performance requirements
template<typename _Tp>
void
operations04()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
const int A[] = {1, 2, 3, 4, 5, 6};
const int B[] = {12, 15, 13, 14, 11};
const int C[] = {11, 12, 13, 14, 15};
const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6};
const int N = sizeof(A) / sizeof(int);
const int M = sizeof(B) / sizeof(int);
const int Q = sizeof(D) / sizeof(int);
list_type list0401(A, A + N);
list_type list0402(B, B + M);
list_type list0403(C, C + M);
list_type list0404(D, D + Q);
list_type list0405(A, A + N);
// sort B
CompLastLt lt;
CompLastLt::reset();
list0402.sort(lt);
VERIFY(list0402 == list0403);
CompLastLt::reset();
list0401.merge(list0402, lt);
VERIFY(list0401 == list0404);
#ifndef _GLIBCXX_DEBUG
VERIFY(lt.count() <= (N + M - 1));
#endif
CompLastEq eq;
CompLastEq::reset();
list0401.unique(eq);
VERIFY(list0401 == list0405);
#ifndef _GLIBCXX_DEBUG
VERIFY(eq.count() == (N + M - 1));
#endif
}

View File

@ -17,122 +17,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include "5.h"
#include <list>
#include <stdexcept>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// Check the splice (and merge) bits of N1599.
template<typename _Tp>
void
operations05()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::allocator_type allocator_type;
const int data1[] = {1, 2, 3, 4, 5};
const int data2[] = {6, 7, 8, 9, 10};
const size_t N1 = sizeof(data1) / sizeof(int);
const size_t N2 = sizeof(data2) / sizeof(int);
allocator_type alloc01(1), alloc02(2);
list_type l01(data1, data1 + N1, alloc01);
const list_type l01_ref = l01;
list_type l02(data2, data2 + N2, alloc02);
const list_type l02_ref = l02;
bool catched = false;
try
{
l01.splice(l01.begin(), l02);
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.splice(l01.begin(), l02, l02.begin());
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.splice(l01.begin(), l02, l02.begin(), l02.end());
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.merge(l02);
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.merge(l02, std::less<int>());
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
}
int main()
{

View File

@ -0,0 +1,134 @@
// 2006-01-19 Paolo Carlini <pcarlini@suse.de>
// Copyright (C) 2006, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 23.2.2.4 list operations [lib.list.ops]
#include <stdexcept>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
// Check the splice (and merge) bits of N1599.
template<typename _Tp>
void
operations05()
{
bool test __attribute__((unused)) = true;
typedef _Tp list_type;
typedef typename list_type::allocator_type allocator_type;
const int data1[] = {1, 2, 3, 4, 5};
const int data2[] = {6, 7, 8, 9, 10};
const size_t N1 = sizeof(data1) / sizeof(int);
const size_t N2 = sizeof(data2) / sizeof(int);
allocator_type alloc01(1), alloc02(2);
list_type l01(data1, data1 + N1, alloc01);
const list_type l01_ref = l01;
list_type l02(data2, data2 + N2, alloc02);
const list_type l02_ref = l02;
bool catched = false;
try
{
l01.splice(l01.begin(), l02);
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.splice(l01.begin(), l02, l02.begin());
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.splice(l01.begin(), l02, l02.begin(), l02.end());
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.merge(l02);
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
catched = false;
try
{
l01.merge(l02, std::less<int>());
}
catch(std::runtime_error&)
{
catched = true;
}
catch(...)
{
VERIFY( false );
}
VERIFY( catched );
VERIFY( l01 == l01_ref );
VERIFY( l02 == l02_ref );
}