bidir_vec_remove_edge.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // NOTE: This test illustrates a longstanding bug in the
  6. // adjacency_list class template. We do not test it because it will
  7. // cause problems until we have time to fix the bug. Annoying? Yes.
  8. #include <iostream>
  9. #include <boost/graph/adjacency_list.hpp>
  10. #include <boost/test/minimal.hpp>
  11. struct edge_prop {
  12. int weight;
  13. };
  14. int
  15. test_main(int, char*[])
  16. {
  17. {
  18. typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
  19. boost::no_property, edge_prop, boost::no_property, boost::vecS> graph;
  20. typedef boost::graph_traits<graph>::edge_descriptor edge;
  21. graph g(2);
  22. edge_prop p1 = { 42 };
  23. edge_prop p2 = { 17 };
  24. add_edge(0, 1, p1, g);
  25. add_edge(1, 0, p2, g);
  26. edge e1 = boost::edge(0, 1, g).first;
  27. edge e2 = boost::edge(1, 0, g).first;
  28. BOOST_CHECK( num_edges(g) == 2 );
  29. BOOST_CHECK( g[e1].weight == 42 );
  30. BOOST_CHECK( g[e2].weight == 17 );
  31. remove_edge(e1, g);
  32. BOOST_CHECK( num_edges(g) == 1 );
  33. // e2 has been invalidated, so grab it again
  34. bool b2;
  35. boost::tie(e2, b2) = boost::edge(1, 0, g);
  36. BOOST_CHECK( b2 );
  37. BOOST_CHECK( g[e2].weight == 17 );
  38. /* Now remove the other edge. Here, the fact that
  39. * stored_ra_edge_iterator keeps an index but does not update it
  40. * when edges are removed. So, this will be incorrect but the
  41. * error may not always show up (use an STL debug mode to see the
  42. * error for sure.)
  43. */
  44. remove_edge(e2, g);
  45. }
  46. return boost::exit_success;
  47. }