From a9a51750b98cbff008e5388946ad65bd221fe079 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Thu, 18 Jun 2009 01:40:44 +0000 Subject: [PATCH] check_construct_destroy.h: New. 2009-06-17 Benjamin Kosnik * 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 --- libstdc++-v3/ChangeLog | 57 +++++++ .../23_containers/list/capacity/1.cc | 45 +---- .../testsuite/23_containers/list/capacity/1.h | 61 +++++++ .../list/check_construct_destroy.cc | 64 +------ .../list/check_construct_destroy.h | 79 +++++++++ .../testsuite/23_containers/list/cons/1.cc | 49 +----- .../testsuite/23_containers/list/cons/1.h | 63 +++++++ .../testsuite/23_containers/list/cons/2.cc | 61 +------ .../testsuite/23_containers/list/cons/2.h | 77 +++++++++ .../testsuite/23_containers/list/cons/3.cc | 32 +--- .../testsuite/23_containers/list/cons/3.h | 48 ++++++ .../testsuite/23_containers/list/cons/4.cc | 45 +---- .../testsuite/23_containers/list/cons/4.h | 61 +++++++ .../testsuite/23_containers/list/cons/5.cc | 35 +--- .../testsuite/23_containers/list/cons/5.h | 51 ++++++ .../testsuite/23_containers/list/cons/6.cc | 48 +----- .../testsuite/23_containers/list/cons/6.h | 64 +++++++ .../testsuite/23_containers/list/cons/7.cc | 49 +----- .../testsuite/23_containers/list/cons/7.h | 65 ++++++++ .../testsuite/23_containers/list/cons/8.cc | 35 +--- .../testsuite/23_containers/list/cons/8.h | 51 ++++++ .../testsuite/23_containers/list/cons/9.cc | 43 +---- .../testsuite/23_containers/list/cons/9.h | 59 +++++++ .../list/cons/clear_allocator.cc | 63 +------ .../23_containers/list/cons/clear_allocator.h | 78 +++++++++ .../testsuite/23_containers/list/init-list.cc | 52 +----- .../testsuite/23_containers/list/init-list.h | 65 ++++++++ .../23_containers/list/modifiers/1.cc | 97 +---------- .../23_containers/list/modifiers/1.h | 113 +++++++++++++ .../23_containers/list/modifiers/2.cc | 70 +------- .../23_containers/list/modifiers/2.h | 86 ++++++++++ .../23_containers/list/modifiers/3.cc | 102 +----------- .../23_containers/list/modifiers/3.h | 118 +++++++++++++ .../list/modifiers/insert/25288.cc | 78 +-------- .../list/modifiers/insert/25288.h | 90 ++++++++++ .../23_containers/list/modifiers/swap/1.cc | 41 +---- .../23_containers/list/modifiers/swap/1.h | 58 +++++++ .../23_containers/list/modifiers/swap/2.cc | 109 +----------- .../23_containers/list/modifiers/swap/2.h | 127 ++++++++++++++ .../23_containers/list/modifiers/swap/3.cc | 138 +--------------- .../23_containers/list/modifiers/swap/3.h | 156 ++++++++++++++++++ .../testsuite/23_containers/list/moveable.cc | 25 +-- .../testsuite/23_containers/list/moveable.h | 41 +++++ .../23_containers/list/operations/1.cc | 52 +----- .../23_containers/list/operations/1.h | 68 ++++++++ .../23_containers/list/operations/2.cc | 38 +---- .../23_containers/list/operations/2.h | 54 ++++++ .../23_containers/list/operations/3.cc | 52 +----- .../23_containers/list/operations/3.h | 68 ++++++++ .../23_containers/list/operations/4.cc | 75 +-------- .../23_containers/list/operations/4.h | 92 +++++++++++ .../23_containers/list/operations/5.cc | 116 +------------ .../23_containers/list/operations/5.h | 134 +++++++++++++++ 53 files changed, 2116 insertions(+), 1582 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/list/capacity/1.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/1.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/2.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/3.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/4.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/5.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/6.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/7.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/8.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/9.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/init-list.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/1.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/2.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/3.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/moveable.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/operations/1.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/operations/2.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/operations/3.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/operations/4.h create mode 100644 libstdc++-v3/testsuite/23_containers/list/operations/5.h diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5abe28411cfd..29747b18c8e8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,60 @@ +2009-06-17 Benjamin Kosnik + + * 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 * python/hook.in: Do not fail when there is no current objfile. diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc index d820776e3a8c..cb6c29ac8d1d 100644 --- a/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/1.cc @@ -15,51 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.2 list capacity [lib.list.capacity] - +#include "1.h" #include -#include - -// 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 -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() diff --git a/libstdc++-v3/testsuite/23_containers/list/capacity/1.h b/libstdc++-v3/testsuite/23_containers/list/capacity/1.h new file mode 100644 index 000000000000..4a2f2bc06a25 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/capacity/1.h @@ -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 +// . + +// 23.2.2.2 list capacity [lib.list.capacity] + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc index a223bc850074..31dacb592537 100644 --- a/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc +++ b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.cc @@ -18,70 +18,12 @@ // . // +#include "check_construct_destroy.h" #include -#include -#include - - -template -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 > >(); + typedef __gnu_test::tracker_allocator allocator_type; + construct_destroy >(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h new file mode 100644 index 000000000000..14da42dc875c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/check_construct_destroy.h @@ -0,0 +1,79 @@ +// 2004-07-26 Matt Austern +// +// 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 +// . +// + +#include +#include + +template +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; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/1.cc b/libstdc++-v3/testsuite/23_containers/list/cons/1.cc index 2228a506fe9a..da469ebb194a 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/1.cc @@ -15,55 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "1.h" #include -#include - -// A nontrivial type. -template - 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/1.h b/libstdc++-v3/testsuite/23_containers/list/cons/1.h new file mode 100644 index 000000000000..2aa48be91466 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/1.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// A nontrivial type. +template + 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 +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; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/2.cc b/libstdc++-v3/testsuite/23_containers/list/cons/2.cc index a38cf7d1bba2..86c59f383f80 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/2.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/2.cc @@ -15,67 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "2.h" #include -#include - -// A nontrivial type. -template - 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 -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 -void -cons022() -{ - // nontrivial value_type - typedef _Tp list_type; - const std::size_t LIST_SIZE = 5; - list_type list0201(LIST_SIZE); -} int main() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/2.h b/libstdc++-v3/testsuite/23_containers/list/cons/2.h new file mode 100644 index 000000000000..eb32896e79a5 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/2.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// A nontrivial type. +template + 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 +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 +void +cons022() +{ + // nontrivial value_type + typedef _Tp list_type; + const std::size_t LIST_SIZE = 5; + list_type list0201(LIST_SIZE); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/3.cc b/libstdc++-v3/testsuite/23_containers/list/cons/3.cc index b067ee17bc2d..f373cc05d8a6 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/3.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/3.cc @@ -15,38 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "3.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/3.h b/libstdc++-v3/testsuite/23_containers/list/cons/3.h new file mode 100644 index 000000000000..983c24ca8aee --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/3.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/4.cc b/libstdc++-v3/testsuite/23_containers/list/cons/4.cc index 0dde9e9eaf4c..d6b58be0481f 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/4.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/4.cc @@ -15,51 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "4.h" #include -#include - -// 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 -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 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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/4.h b/libstdc++-v3/testsuite/23_containers/list/cons/4.h new file mode 100644 index 000000000000..bf2e51c138d1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/4.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/5.cc b/libstdc++-v3/testsuite/23_containers/list/cons/5.cc index be8b5921aebc..de86dccd696f 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/5.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/5.cc @@ -15,41 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "5.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/5.h b/libstdc++-v3/testsuite/23_containers/list/cons/5.h new file mode 100644 index 000000000000..5c273a322e72 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/5.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/6.cc b/libstdc++-v3/testsuite/23_containers/list/cons/6.cc index c2ecc59de255..c1a2baedca2b 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/6.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/6.cc @@ -15,54 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "6.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/6.h b/libstdc++-v3/testsuite/23_containers/list/cons/6.h new file mode 100644 index 000000000000..b247e5563cb8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/6.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/7.cc b/libstdc++-v3/testsuite/23_containers/list/cons/7.cc index 9a626a6234f3..0f3de3c6763e 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/7.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/7.cc @@ -15,55 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "7.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/7.h b/libstdc++-v3/testsuite/23_containers/list/cons/7.h new file mode 100644 index 000000000000..1ebd7a5cfaa7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/7.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/8.cc b/libstdc++-v3/testsuite/23_containers/list/cons/8.cc index f93520c54062..16d888b44725 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/8.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/8.cc @@ -15,41 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "8.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/8.h b/libstdc++-v3/testsuite/23_containers/list/cons/8.h new file mode 100644 index 000000000000..4aed16b81d9c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/8.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/9.cc b/libstdc++-v3/testsuite/23_containers/list/cons/9.cc index 87cb0270c400..908454453a25 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/9.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/9.cc @@ -15,49 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.1 list constructors, copy, and assignment - +#include "9.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/9.h b/libstdc++-v3/testsuite/23_containers/list/cons/9.h new file mode 100644 index 000000000000..90c3fd0540e3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/9.h @@ -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 +// . + +// 23.2.2.1 list constructors, copy, and assignment + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc index 82a47ade754d..cb186d321cbc 100644 --- a/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc +++ b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.cc @@ -15,69 +15,8 @@ // with this library; see the file COPYING3. If not see // . +#include "clear_allocator.h" #include -#include - -using namespace std; -using __gnu_cxx::new_allocator; - -template - class clear_alloc : public new_allocator - { - public: - - template - struct rebind - { typedef clear_alloc other; }; - - virtual void clear() throw() - { } - - clear_alloc() throw() - { } - - clear_alloc(clear_alloc const&) throw() : new_allocator() - { } - - template - clear_alloc(clear_alloc const&) throw() - { } - - virtual ~clear_alloc() throw() - { this->clear(); } - - T* allocate(typename new_allocator::size_type n, const void *hint = 0) - { - this->clear(); - return new_allocator::allocate(n, hint); - } - - void deallocate(T *ptr, typename new_allocator::size_type n) - { - this->clear(); - new_allocator::deallocate(ptr, n); - } - }; - -template - 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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h new file mode 100644 index 000000000000..3a53751c9624 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/cons/clear_allocator.h @@ -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 +// . + +#include + +using namespace std; +using __gnu_cxx::new_allocator; + +template + class clear_alloc : public new_allocator + { + public: + + template + struct rebind + { typedef clear_alloc other; }; + + virtual void clear() throw() + { } + + clear_alloc() throw() + { } + + clear_alloc(clear_alloc const&) throw() : new_allocator() + { } + + template + clear_alloc(clear_alloc const&) throw() + { } + + virtual ~clear_alloc() throw() + { this->clear(); } + + T* allocate(typename new_allocator::size_type n, const void *hint = 0) + { + this->clear(); + return new_allocator::allocate(n, hint); + } + + void deallocate(T *ptr, typename new_allocator::size_type n) + { + this->clear(); + new_allocator::deallocate(ptr, n); + } + }; + +template + 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; + } diff --git a/libstdc++-v3/testsuite/23_containers/list/init-list.cc b/libstdc++-v3/testsuite/23_containers/list/init-list.cc index 261ef084f097..db6bc3b69375 100644 --- a/libstdc++-v3/testsuite/23_containers/list/init-list.cc +++ b/libstdc++-v3/testsuite/23_containers/list/init-list.cc @@ -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 @@ // . // -// { dg-options "-std=gnu++0x" } - +#include "init-list.h" #include -#include - -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/init-list.h b/libstdc++-v3/testsuite/23_containers/list/init-list.h new file mode 100644 index 000000000000..a391ffdad671 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/init-list.h @@ -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 +// . +// + +#include + +template +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; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc index b1c85f0511cd..cf8c20a6578d 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.cc @@ -15,103 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.3 list modifiers [lib.list.modifiers] - +#include "1.h" #include -#include - -// range and fill insert/erase + clear -// missing: o fill insert disguised as a range insert in all its variants -// o exception effects -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/1.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.h new file mode 100644 index 000000000000..f26fd8854859 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/1.h @@ -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 +// . + +// 23.2.2.3 list modifiers [lib.list.modifiers] + +#include + +// range and fill insert/erase + clear +// missing: o fill insert disguised as a range insert in all its variants +// o exception effects +template +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()); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc index da39397d098b..ee9b54923df7 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc @@ -15,76 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.3 list modifiers [lib.list.modifiers] - +#include "2.h" #include -#include - -// general single insert/erase + swap -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/2.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.h new file mode 100644 index 000000000000..64a348769e22 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/2.h @@ -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 +// . + +// 23.2.2.3 list modifiers [lib.list.modifiers] + +#include + +// general single insert/erase + swap +template +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc index b6a41e3dc45a..8454c3f46fae 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.cc @@ -15,108 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.3 list modifiers [lib.list.modifiers] - +#include "3.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/3.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.h new file mode 100644 index 000000000000..43e5c58ec607 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/3.h @@ -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 +// . + +// 23.2.2.3 list modifiers [lib.list.modifiers] + +#include + +// 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 +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc index e108288586ec..e9195ddbc643 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.cc @@ -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 // . -// 23.2.2.3 list modifiers [lib.list.modifiers] - -// { dg-require-time "" } - +#include "25288.h" #include -#include -#include - -// libstdc++/25288 -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h new file mode 100644 index 000000000000..c3ec6628f3d9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/insert/25288.h @@ -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 +// . + +// 23.2.2.3 list modifiers [lib.list.modifiers] + +#include +#include + +// libstdc++/25288 +template +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 ); + } +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc index c66ead57c765..d9bd9a2194e1 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc @@ -15,12 +15,8 @@ // with this library; see the file COPYING3. If not see // . +#include "1.h" #include -#include - -struct T { int i; }; - -int swap_calls; namespace std { @@ -30,41 +26,6 @@ namespace std { ++swap_calls; } } -// Should use list specialization for swap. -template -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 -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 >; -#endif - // See c++/13658 for background info. int main() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h new file mode 100644 index 000000000000..64619b42470d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.h @@ -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 +// . + +#include +#include + +struct T { int i; }; + +int swap_calls; + +// Should use list specialization for swap. +template +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 +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 >; +#endif diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc index e31c0fb5924f..7bd75a39e3c3 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc @@ -17,115 +17,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.3 list::swap - +#include "2.h" #include -#include -#include - -// uneq_allocator as a non-empty allocator. -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h new file mode 100644 index 000000000000..2cd68f60c7a1 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.h @@ -0,0 +1,127 @@ +// 2005-12-20 Paolo Carlini + +// 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 +// . + +// 23.2.2.3 list::swap + +#include +#include + +// uneq_allocator as a non-empty allocator. +template +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) ); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc index c0e0f65bf64e..f994e9b4ae13 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc @@ -17,144 +17,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.3 list::swap - +#include "3.h" #include -#include -#include - -// uneq_allocator, two different personalities. -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h new file mode 100644 index 000000000000..b4f2cd097d8e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.h @@ -0,0 +1,156 @@ +// 2005-12-20 Paolo Carlini + +// 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 +// . + +// 23.2.2.3 list::swap + +#include +#include + +// uneq_allocator, two different personalities. +template +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 ); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/moveable.cc b/libstdc++-v3/testsuite/23_containers/list/moveable.cc index dc245b1ca009..fbe06634e6ff 100644 --- a/libstdc++-v3/testsuite/23_containers/list/moveable.cc +++ b/libstdc++-v3/testsuite/23_containers/list/moveable.cc @@ -17,31 +17,8 @@ // with this library; see the file COPYING3. If not see // . -// 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 -#include -#include - -template - 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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/moveable.h b/libstdc++-v3/testsuite/23_containers/list/moveable.h new file mode 100644 index 000000000000..1f11d6221e79 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/moveable.h @@ -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 +// . + +// 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 +#include + +template + 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 ); + } diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/1.cc b/libstdc++-v3/testsuite/23_containers/list/operations/1.cc index d44e1c706125..2c98213e2a52 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/1.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/1.cc @@ -15,58 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.4 list operations [lib.list.ops] - +#include "1.h" #include -#include - -// splice(p, x) + remove + reverse -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/1.h b/libstdc++-v3/testsuite/23_containers/list/operations/1.h new file mode 100644 index 000000000000..2f3f9df94659 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/1.h @@ -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 +// . + +// 23.2.2.4 list operations [lib.list.ops] + +#include + +// splice(p, x) + remove + reverse +template +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()); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/2.cc b/libstdc++-v3/testsuite/23_containers/list/operations/2.cc index 743b176b38f3..100066fc29bc 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/2.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/2.cc @@ -15,44 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.4 list operations [lib.list.ops] - +#include "2.h" #include -#include - -// splice(p, x, i) + remove_if + operator== -template -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/2.h b/libstdc++-v3/testsuite/23_containers/list/operations/2.h new file mode 100644 index 000000000000..8eb3da4e7809 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/2.h @@ -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 +// . + +// 23.2.2.4 list operations [lib.list.ops] + +#include + +// splice(p, x, i) + remove_if + operator== +template +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/3.cc b/libstdc++-v3/testsuite/23_containers/list/operations/3.cc index 83d00133c494..53570b4a694b 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/3.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/3.cc @@ -15,58 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.4 list operations [lib.list.ops] - +#include "3.h" #include -#include - -// splice(p, x, f, l) + sort + merge + unique -template -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) { diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/3.h b/libstdc++-v3/testsuite/23_containers/list/operations/3.h new file mode 100644 index 000000000000..4d28daea12bb --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/3.h @@ -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 +// . + +// 23.2.2.4 list operations [lib.list.ops] + +#include + +// splice(p, x, f, l) + sort + merge + unique +template +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); +} diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/4.cc b/libstdc++-v3/testsuite/23_containers/list/operations/4.cc index 37b983a39a2e..a220b9b331f0 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/4.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/4.cc @@ -15,81 +15,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.4 list operations [lib.list.ops] - +#include "4.h" #include -#include - -// 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 -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() { diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/4.h b/libstdc++-v3/testsuite/23_containers/list/operations/4.h new file mode 100644 index 000000000000..0a3ea4d234d4 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/4.h @@ -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 +// . + +// 23.2.2.4 list operations [lib.list.ops] + +#include + +// 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 +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 +} + diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/5.cc b/libstdc++-v3/testsuite/23_containers/list/operations/5.cc index ae1939c8824f..ad99c27ae42a 100644 --- a/libstdc++-v3/testsuite/23_containers/list/operations/5.cc +++ b/libstdc++-v3/testsuite/23_containers/list/operations/5.cc @@ -17,122 +17,8 @@ // with this library; see the file COPYING3. If not see // . -// 23.2.2.4 list operations [lib.list.ops] - +#include "5.h" #include -#include -#include -#include - -// Check the splice (and merge) bits of N1599. -template -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()); - } - catch(std::runtime_error&) - { - catched = true; - } - catch(...) - { - VERIFY( false ); - } - VERIFY( catched ); - VERIFY( l01 == l01_ref ); - VERIFY( l02 == l02_ref ); -} int main() { diff --git a/libstdc++-v3/testsuite/23_containers/list/operations/5.h b/libstdc++-v3/testsuite/23_containers/list/operations/5.h new file mode 100644 index 000000000000..2b54d5195ffd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/operations/5.h @@ -0,0 +1,134 @@ +// 2006-01-19 Paolo Carlini + +// 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 +// . + +// 23.2.2.4 list operations [lib.list.ops] + +#include +#include +#include + +// Check the splice (and merge) bits of N1599. +template +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()); + } + catch(std::runtime_error&) + { + catched = true; + } + catch(...) + { + VERIFY( false ); + } + VERIFY( catched ); + VERIFY( l01 == l01_ref ); + VERIFY( l02 == l02_ref ); +} -- 2.39.5