1 | // (C) Copyright 2004 Douglas Gregor and Jeremy Siek |
2 | // Distributed under the Boost Software License, Version 1.0. (See |
3 | // accompanying file LICENSE_1_0.txt or copy at |
4 | // http://www.boost.org/LICENSE_1_0.txt) |
5 | |
6 | // NOTE: This test illustrates a longstanding bug in the |
7 | // adjacency_list class template. We do not test it because it will |
8 | // cause problems until we have time to fix the bug. Annoying? Yes. |
9 | |
10 | #include <iostream> |
11 | #include <boost/graph/adjacency_list.hpp> |
12 | #include <boost/core/lightweight_test.hpp> |
13 | |
14 | struct edge_prop |
15 | { |
16 | int weight; |
17 | }; |
18 | |
19 | int main(int, char*[]) |
20 | { |
21 | { |
22 | typedef boost::adjacency_list< boost::vecS, boost::vecS, |
23 | boost::bidirectionalS, boost::no_property, edge_prop, |
24 | boost::no_property, boost::vecS > |
25 | graph; |
26 | typedef boost::graph_traits< graph >::edge_descriptor edge; |
27 | |
28 | graph g(2); |
29 | |
30 | edge_prop p1 = { .weight: 42 }; |
31 | edge_prop p2 = { .weight: 17 }; |
32 | add_edge(u: 0, v: 1, p: p1, g_&: g); |
33 | add_edge(u: 1, v: 0, p: p2, g_&: g); |
34 | |
35 | edge e1 = boost::edge(u: 0, v: 1, g_: g).first; |
36 | edge e2 = boost::edge(u: 1, v: 0, g_: g).first; |
37 | BOOST_TEST(num_edges(g) == 2); |
38 | BOOST_TEST(g[e1].weight == 42); |
39 | BOOST_TEST(g[e2].weight == 17); |
40 | remove_edge(e: e1, g_&: g); |
41 | BOOST_TEST(num_edges(g) == 1); |
42 | |
43 | // e2 has been invalidated, so grab it again |
44 | bool b2; |
45 | boost::tie(t0&: e2, t1&: b2) = boost::edge(u: 1, v: 0, g_: g); |
46 | BOOST_TEST(b2); |
47 | BOOST_TEST(g[e2].weight == 17); |
48 | |
49 | /* Now remove the other edge. Here, the fact that |
50 | * stored_ra_edge_iterator keeps an index but does not update it |
51 | * when edges are removed. So, this will be incorrect but the |
52 | * error may not always show up (use an STL debug mode to see the |
53 | * error for sure.) |
54 | */ |
55 | remove_edge(e: e2, g_&: g); |
56 | } |
57 | return boost::report_errors(); |
58 | } |
59 | |