This documentation is being rewritten. If something looks off, please cross-check with the Boost 1.91.0 Boost.Graph docs and open an issue.

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

Graph

The graph type. Must model Bidirectional Graph.

VertexDescriptor

The vertex-descriptor type. Defaults to graph_traits<Graph>::vertex_descriptor. The parameter exists because the generator is typically instantiated inside the graph class’s declaration, where graph_traits<Graph> cannot yet be resolved.

InEdgeIter

The source in-edge iterator type. Defaults to graph_traits<Graph>::in_edge_iterator, with the same caveat as above.

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