inv_adjacency_iterator_generator
Synthesizes a vertex-iterator out of an existing in-edge iterator. Reads each in-edge and yields its source vertex.
Defined in: <boost/graph/adjacency_iterator.hpp>
| You almost certainly do not need this page. |
Most BGL users just call inv_adjacent_vertices(v, g) on a graph that
models Bidirectional Graph
(such as adjacency_list<…, bidirectionalS> or
adjacency_list<…, undirectedS>). This page is for people implementing
a new graph class that models Bidirectional Graph and who want the
compiler to give them the reverse adjacency iterator for free.
Example
// The inverse adjacency iterator iterates SOURCE vertices of in-edges.
//
// Most BGL users never construct one directly — they call
// `inv_adjacent_vertices(v, g)` on a BidirectionalGraph. You only need
// `inv_adjacency_iterator_generator` when implementing a new graph
// type that models BidirectionalGraph and wants to synthesize its
// `inv_adjacency_iterator` from its `in_edge_iterator`.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_iterator.hpp>
#include <iostream>
using namespace boost;
using Graph = adjacency_list<vecS, vecS, bidirectionalS>;
int main() {
Graph g(4);
add_edge(1, 0, g);
add_edge(2, 0, g);
add_edge(3, 0, g);
// Everyday path: inv_adjacent_vertices returns an (iterator, iterator)
// pair whose value_type is vertex_descriptor.
std::cout << "predecessors of 0:";
for (auto v : make_iterator_range(inv_adjacent_vertices(0, g))) {
std::cout << ' ' << v;
}
std::cout << '\n';
}
predecessors of 0: 1 2 3
For any existing BGL graph class you never need to instantiate the
generator — the class already exposes
graph_traits<Graph>::inv_adjacency_iterator.
Synopsis
namespace boost {
template <class Graph,
class VertexDescriptor = typename graph_traits<Graph>::vertex_descriptor,
class InEdgeIter = typename graph_traits<Graph>::in_edge_iterator>
class inv_adjacency_iterator_generator {
public:
typedef /* iterator_adaptor instantiation */ type;
};
} // namespace boost
Template parameters
| Parameter | Description |
|---|---|
|
The graph type. Must model Bidirectional Graph. |
|
The vertex-descriptor type. Defaults to
|
|
The source in-edge iterator type. Defaults to
|
Members
inv_adjacency_iterator_generator<…>::type satisfies the
Multi-Pass Input Iterator
concept. It exposes every operator required of a
Random Access Iterator,
except that reference equals value_type, so operator*() returns
by value.
Constructor:
inv_adjacency_iterator_generator<…>::type(const InEdgeIter& it, const Graph* g);
See also
-
BidirectionalGraph concept —
inv_adjacent_vertices(v, g), what you probably want. -
adjacency_iterator_generator— the forward counterpart.