Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
23.list.insert.stdcxx-331.cpp
Go to the documentation of this file.
1
27#include <list>
28#include <cassert>
29
30static int throw_inx = -1;
31
32class ListItem
33{
34public:
35 static int count_;
36
37 void test ()
38 {
39 if (throw_inx == count_)
40 throw count_;
41
42 ++count_;
43 }
44
45 ListItem () { test (); }
46
47 ListItem (const ListItem&) { test (); }
48
49 ~ListItem () { --count_; }
50};
51
52int ListItem::count_ = 0;
53
54
55int main ()
56{
57 typedef std::list<ListItem> List;
58 ListItem items [20];
59 List lst (1);
60
61 bool thrown = false;
62 throw_inx = 10;
63
64 List::iterator it = lst.begin ();
65 ListItem & ref = *it;
66
67 try {
69 lst.insert (it, 20, items [0]);
70 } catch (...) {
71 thrown = true;
72 }
73
74 assert (thrown);
75 assert (it == lst.begin ());
76 assert (&ref == &*lst.begin ());
77 assert (1 == lst.size ());
79
80 try {
82 lst.insert (it, items, items + 20);
83 } catch (...) {
84 thrown = true;
85 }
86
87 assert (thrown);
88 assert (it == lst.begin ());
89 assert (&ref == &*lst.begin ());
90 assert (1 == lst.size ());
92
93 return 0;
94}
#define assert(expr)
Definition _cassert.h:40
ListItem(const ListItem &)