• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main(int,char * [])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 = { 42 };
31         edge_prop p2 = { 17 };
32         add_edge(0, 1, p1, g);
33         add_edge(1, 0, p2, g);
34 
35         edge e1 = boost::edge(0, 1, g).first;
36         edge e2 = boost::edge(1, 0, 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(e1, g);
41         BOOST_TEST(num_edges(g) == 1);
42 
43         // e2 has been invalidated, so grab it again
44         bool b2;
45         boost::tie(e2, b2) = boost::edge(1, 0, 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(e2, g);
56     }
57     return boost::report_errors();
58 }
59