copy_graph
Copies all vertices and edges from one graph into another, along with their properties.
Complexity: O(V + E)
Defined in: <boost/graph/copy.hpp>
copy_graph internally requires a vertex_index property map.
With VertexList=listS, the call will not compile unless you supply your
own vertex index.
|
Example
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/copy.hpp>
int main() {
using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS>;
Graph g;
boost::add_edge(0, 1, g);
boost::add_edge(1, 2, g);
boost::add_edge(2, 3, g);
Graph g_copy;
boost::copy_graph(g, g_copy);
std::cout << "Original: " << num_vertices(g) << " vertices, "
<< num_edges(g) << " edges\n";
std::cout << "Copy: " << num_vertices(g_copy) << " vertices, "
<< num_edges(g_copy) << " edges\n";
}
Original: 4 vertices, 3 edges
Copy: 4 vertices, 3 edges
(1) Named parameter version
template <class VertexListGraph, class MutableGraph,
class P, class T, class R>
void copy_graph(
const VertexListGraph& G, MutableGraph& G_copy,
const bgl_named_params<P, T, R>& params);
| Direction | Parameter | Description |
|---|---|---|
IN |
|
A directed or undirected graph. The graph type must be a model of Vertex List Graph. |
OUT |
|
The resulting copy of the graph. The graph type must be a model of Mutable Graph. |
Named Parameters
| Direction | Parameter | Description |
|---|---|---|
IN |
|
This is a Binary Function that copies the properties of a vertex in the original graph into the corresponding vertex in the copy. |
IN |
|
This is a Binary Function that copies the properties of an edge in the original graph into the corresponding edge in the copy. |
IN |
|
The vertex index map type must be a model of Readable Property Map and must map the vertex descriptors of |
UTIL/OUT |
|
This maps vertices in the original graph to vertices in the copy. |
(2) Positional version
template <class VertexListGraph, class MutableGraph>
void copy_graph(const VertexListGraph& G, MutableGraph& G_copy);
Equivalent to (1) with every named parameter left at its default. Uses the default vertex/edge copiers (via vertex_all / edge_all property tags) and get(vertex_index, G).
| Direction | Parameter | Description |
|---|---|---|
IN |
|
Same as (1). |
OUT |
|
Same as (1). |