diff --git a/include/boost/graph/detail/adjacency_list.hpp b/include/boost/graph/detail/adjacency_list.hpp index c1a2ada23..7fb2c4936 100644 --- a/include/boost/graph/detail/adjacency_list.hpp +++ b/include/boost/graph/detail/adjacency_list.hpp @@ -2069,15 +2069,20 @@ namespace detail inline void reindex_edge_list( EdgeList& el, vertex_descriptor u, boost::disallow_parallel_edge_tag) { - for (typename EdgeList::iterator ei = el.begin(); ei != el.end(); ++ei) + typename EdgeList::iterator ei = el.begin(), e_end = el.end(); + while (ei != e_end) { if (ei->get_target() > u) { typename EdgeList::value_type ce = *ei; + ++ei; el.erase(ce); --ce.get_target(); el.insert(ce); } + else { + ++ei; + } } } } // namespace detail diff --git a/test/delete_edge.cpp b/test/delete_edge.cpp index f2ab4ee52..2abbfc764 100644 --- a/test/delete_edge.cpp +++ b/test/delete_edge.cpp @@ -55,5 +55,23 @@ int main(int argc, char* argv[]) BOOST_TEST(m_graph[ed1] == EDGE_VAL); + // https://github.com/boostorg/graph/issues/268 + // 1. Undirected: + { + boost::adjacency_list g; + boost::add_edge(2, 0, g); + boost::remove_vertex(1, g); + BOOST_TEST(num_vertices(g) == 2); + BOOST_TEST(num_edges(g) == 1); + } + // 2. Directed: + { + boost::adjacency_list g; + boost::add_edge(2, 0, g); + boost::remove_vertex(1, g); + BOOST_TEST(num_vertices(g) == 2); + BOOST_TEST(num_edges(g) == 1); + } + return boost::report_errors(); }