/* * ex_remove_if.cpp * * Formatted with tabstops = 4 * */ #include #include #include #include #include template class Remover { public: Remover(const WMap& weights, int threshold) : m_weights(weights), m_threshold(threshold) {} template bool operator()(ED w) const { return m_weights[w] < m_threshold; } private: const WMap& m_weights; int m_threshold; }; using namespace boost; int main() { // create typedefs for the Graph, Edge and weight_map types typedef adjacency_list > Graph; typedef std::pair Edge; typedef property_map::type weight_map_type; // Make convenient labels for the vertices enum { A, B, C, D, E, N }; const int num_vertices = N; const char* name = "ABCDE"; int weights[] = { 1, 2, 1, 2, 7, 3, 1, 3, 1 }; Edge edge_array[] = { Edge(A, C), Edge(B, B), Edge(B, D), Edge(B, E), Edge(C, B), Edge(C, D), Edge(D, E), Edge(E, A), Edge(E, B) }; const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]); // declare a graph object Graph g(edge_array, edge_array + num_edges, weights, num_vertices); // print the graph before deleting edges std::cout << "Graph Before remove_edge_if:\n"; print_graph(g, name); // remove edges of weight < 2 Remover r(get(edge_weight, g), 2); remove_edge_if(r, g); // print the graph after deleting edges std::cout << "\nGraph After remove_edge_if:\n"; print_graph(g, name); return 0; }