adjacency_iterator_generator
Synthesizes a vertex-iterator out of an existing out-edge iterator. Reads each out-edge and yields its target vertex.
Defined in: <boost/graph/adjacency_iterator.hpp>
| You almost certainly do not need this page. |
Most BGL users just call adjacent_vertices(v, g) on any graph that
models Adjacency Graph (which every
built-in BGL graph class does). This page is for people implementing
a new graph class that models Incidence
Graph and who want the compiler to give them the adjacency iterator for
free.
Example
// Most BGL users never construct an adjacency_iterator directly —
// they call `adjacent_vertices(v, g)`, which returns a pair of them.
//
// This example shows the plain-vanilla use via adjacent_vertices, then
// the `type` exposed by adjacency_iterator_generator for the same graph.
// You only reach for the generator when implementing a new graph type
// that models IncidenceGraph but not (yet) AdjacencyGraph.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_iterator.hpp>
#include <iostream>
#include <type_traits>
using namespace boost;
using Graph = adjacency_list<vecS, vecS, directedS>;
int main() {
Graph g(4);
add_edge(0, 1, g);
add_edge(0, 2, g);
add_edge(0, 3, g);
// Everyday path: adjacent_vertices returns an (iterator, iterator) pair
// whose value_type is vertex_descriptor.
std::cout << "neighbors of 0:";
for (auto v : make_iterator_range(adjacent_vertices(0, g))) {
std::cout << ' ' << v;
}
std::cout << '\n';
// The generator produces a type equivalent to what adjacency_list
// already exposes as graph_traits<Graph>::adjacency_iterator.
using Generated = adjacency_iterator_generator<
Graph,
graph_traits<Graph>::vertex_descriptor,
graph_traits<Graph>::out_edge_iterator>::type;
using Existing = graph_traits<Graph>::adjacency_iterator;
std::cout << "generator matches graph_traits: "
<< std::boolalpha << std::is_same<Generated, Existing>::value
<< '\n';
}
neighbors of 0: 1 2 3
generator matches graph_traits: true
The example shows both paths:
-
adjacent_vertices(v, g)— the everyday way to iterate over neighbors. -
adjacency_iterator_generator<…>::type— the type you would publish asadjacency_iteratorin your own graph class.
For existing graph types like adjacency_list, the generator produces
the same type that graph_traits already exposes; there is no reason
to instantiate it yourself.
Synopsis
namespace boost {
template <class Graph,
class VertexDescriptor = typename graph_traits<Graph>::vertex_descriptor,
class OutEdgeIter = typename graph_traits<Graph>::out_edge_iterator>
class adjacency_iterator_generator {
public:
typedef /* iterator_adaptor instantiation */ type;
};
} // namespace boost
Template parameters
| Parameter | Description |
|---|---|
|
The graph type. Must model Incidence Graph. |
|
The vertex-descriptor type. Defaults to
|
|
The source out-edge iterator type. Defaults to
|
Members
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:
adjacency_iterator_generator<…>::type(const OutEdgeIter& it, const Graph* g);
See also
-
AdjacencyGraph concept —
adjacent_vertices(v, g), what you probably want. -
inv_adjacency_iterator_generator— the bidirectional counterpart.