2008-05-29 Andy Hutchinson <hutchinsonandy@aim.com>
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / operators / 5.cc
blob22f504691d96f77cb5b7523a86199417276693e9
1 // 2006-01-19 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // 23.2.2.4 list operations [lib.list.ops]
23 #include <list>
24 #include <stdexcept>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // Check the splice (and merge) bits of N1599.
29 void
30 test01()
32 bool test __attribute__((unused)) = true;
34 typedef __gnu_test::uneq_allocator<int> my_alloc;
35 typedef std::list<int, my_alloc> my_list;
37 const int data1[] = {1, 2, 3, 4, 5};
38 const int data2[] = {6, 7, 8, 9, 10};
39 const size_t N1 = sizeof(data1) / sizeof(int);
40 const size_t N2 = sizeof(data2) / sizeof(int);
42 my_alloc alloc01(1), alloc02(2);
44 my_list l01(data1, data1 + N1, alloc01);
45 const my_list l01_ref = l01;
47 my_list l02(data2, data2 + N2, alloc02);
48 const my_list l02_ref = l02;
50 bool catched = false;
52 try
54 l01.splice(l01.begin(), l02);
56 catch(std::runtime_error&)
58 catched = true;
60 catch(...)
62 VERIFY( false );
64 VERIFY( catched );
65 VERIFY( l01 == l01_ref );
66 VERIFY( l02 == l02_ref );
68 catched = false;
69 try
71 l01.splice(l01.begin(), l02, l02.begin());
73 catch(std::runtime_error&)
75 catched = true;
77 catch(...)
79 VERIFY( false );
81 VERIFY( catched );
82 VERIFY( l01 == l01_ref );
83 VERIFY( l02 == l02_ref );
85 catched = false;
86 try
88 l01.splice(l01.begin(), l02, l02.begin(), l02.end());
90 catch(std::runtime_error&)
92 catched = true;
94 catch(...)
96 VERIFY( false );
98 VERIFY( catched );
99 VERIFY( l01 == l01_ref );
100 VERIFY( l02 == l02_ref );
102 catched = false;
105 l01.merge(l02);
107 catch(std::runtime_error&)
109 catched = true;
111 catch(...)
113 VERIFY( false );
115 VERIFY( catched );
116 VERIFY( l01 == l01_ref );
117 VERIFY( l02 == l02_ref );
119 catched = false;
122 l01.merge(l02, std::less<int>());
124 catch(std::runtime_error&)
126 catched = true;
128 catch(...)
130 VERIFY( false );
132 VERIFY( catched );
133 VERIFY( l01 == l01_ref );
134 VERIFY( l02 == l02_ref );
137 int main()
139 test01();
140 return 0;