Imported Upstream version 4.7.3
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 23_containers / list / operations / 5.h
1 // 2006-01-19  Paolo Carlini  <pcarlini@suse.de>
2
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.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
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/>.
19
20 // 23.2.2.4 list operations [lib.list.ops]
21
22 #include <stdexcept>
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
25
26 // Check the splice (and merge) bits of N1599.
27 template<typename _Tp>
28 void
29 operations05()
30 {
31   bool test __attribute__((unused)) = true;
32   
33   typedef _Tp list_type;
34   typedef typename list_type::allocator_type allocator_type;
35
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);
40   
41   allocator_type alloc01(1), alloc02(2);
42
43   list_type l01(data1, data1 + N1, alloc01);
44   const list_type l01_ref = l01;
45
46   list_type l02(data2, data2 + N2, alloc02);
47   const list_type l02_ref = l02;
48
49   bool catched = false;
50
51   try
52     {
53       l01.splice(l01.begin(), l02);
54     }
55   catch(std::runtime_error&)
56     {
57       catched = true;
58     }
59   catch(...)
60     {
61       VERIFY( false );
62     }
63   VERIFY( catched );
64   VERIFY( l01 == l01_ref );
65   VERIFY( l02 == l02_ref );
66   
67   catched = false;
68   try
69     {
70       l01.splice(l01.begin(), l02, l02.begin());
71     }
72   catch(std::runtime_error&)
73     {
74       catched = true;
75     }
76   catch(...)
77     {
78       VERIFY( false );
79     }
80   VERIFY( catched );
81   VERIFY( l01 == l01_ref );
82   VERIFY( l02 == l02_ref );
83
84   catched = false;
85   try
86     {
87       l01.splice(l01.begin(), l02, l02.begin(), l02.end());
88     }
89   catch(std::runtime_error&)
90     {
91       catched = true;
92     }
93   catch(...)
94     {
95       VERIFY( false );
96     }
97   VERIFY( catched );
98   VERIFY( l01 == l01_ref );
99   VERIFY( l02 == l02_ref );
100
101   catched = false;
102   try
103     {
104       l01.merge(l02);
105     }
106   catch(std::runtime_error&)
107     {
108       catched = true;
109     }
110   catch(...)
111     {
112       VERIFY( false );
113     }
114   VERIFY( catched );
115   VERIFY( l01 == l01_ref );
116   VERIFY( l02 == l02_ref );
117
118   catched = false;
119   try
120     {
121       l01.merge(l02, std::less<int>());
122     }
123   catch(std::runtime_error&)
124     {
125       catched = true;
126     }
127   catch(...)
128     {
129       VERIFY( false );
130     }
131   VERIFY( catched );
132   VERIFY( l01 == l01_ref );
133   VERIFY( l02 == l02_ref );
134 }