2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / operations / 5.h
blob2b54d5195ffdee664d8742ebc3dabc488da7e189
1 // 2006-01-19 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 23.2.2.4 list operations [lib.list.ops]
22 #include <stdexcept>
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // Check the splice (and merge) bits of N1599.
27 template<typename _Tp>
28 void
29 operations05()
31 bool test __attribute__((unused)) = true;
33 typedef _Tp list_type;
34 typedef typename list_type::allocator_type allocator_type;
36 const int data1[] = {1, 2, 3, 4, 5};
37 const int data2[] = {6, 7, 8, 9, 10};
38 const size_t N1 = sizeof(data1) / sizeof(int);
39 const size_t N2 = sizeof(data2) / sizeof(int);
41 allocator_type alloc01(1), alloc02(2);
43 list_type l01(data1, data1 + N1, alloc01);
44 const list_type l01_ref = l01;
46 list_type l02(data2, data2 + N2, alloc02);
47 const list_type l02_ref = l02;
49 bool catched = false;
51 try
53 l01.splice(l01.begin(), l02);
55 catch(std::runtime_error&)
57 catched = true;
59 catch(...)
61 VERIFY( false );
63 VERIFY( catched );
64 VERIFY( l01 == l01_ref );
65 VERIFY( l02 == l02_ref );
67 catched = false;
68 try
70 l01.splice(l01.begin(), l02, l02.begin());
72 catch(std::runtime_error&)
74 catched = true;
76 catch(...)
78 VERIFY( false );
80 VERIFY( catched );
81 VERIFY( l01 == l01_ref );
82 VERIFY( l02 == l02_ref );
84 catched = false;
85 try
87 l01.splice(l01.begin(), l02, l02.begin(), l02.end());
89 catch(std::runtime_error&)
91 catched = true;
93 catch(...)
95 VERIFY( false );
97 VERIFY( catched );
98 VERIFY( l01 == l01_ref );
99 VERIFY( l02 == l02_ref );
101 catched = false;
104 l01.merge(l02);
106 catch(std::runtime_error&)
108 catched = true;
110 catch(...)
112 VERIFY( false );
114 VERIFY( catched );
115 VERIFY( l01 == l01_ref );
116 VERIFY( l02 == l02_ref );
118 catched = false;
121 l01.merge(l02, std::less<int>());
123 catch(std::runtime_error&)
125 catched = true;
127 catch(...)
129 VERIFY( false );
131 VERIFY( catched );
132 VERIFY( l01 == l01_ref );
133 VERIFY( l02 == l02_ref );