= edge_predecessor_recorder

Records the predecessor _edge_ of each vertex in a property map, an efficient way
to encode the search tree traversed during a graph search. Use this instead of
xref:visitors/predecessor_recorder.adoc[`predecessor_recorder`] (which records the
predecessor vertex) when a graph has parallel edges and you need to know which
specific edge the search used to reach a vertex.

*Defined in:* `<boost/graph/visitors.hpp>` +
*Models:* xref:visitors/EventVisitor.adoc[EventVisitor] +
*Typical event:* `on_tree_edge` or `on_relax_edge` (edge events only; cannot be
used with vertex events)

To use it, wrap it in an algorithm adaptor and optionally combine it with other
event visitors; see the xref:visitors/overview.adoc[visitors overview].

== Synopsis

[source,cpp]
----
template <typename PredEdgeMap, typename EventTag>
struct edge_predecessor_recorder {
  typedef EventTag event_filter;
  edge_predecessor_recorder(PredEdgeMap pa);

  template <class Edge, class Graph>
  void operator()(Edge e, const Graph& g);
};

template <typename PredEdgeMap, typename EventTag>
edge_predecessor_recorder<PredEdgeMap, EventTag>
record_edge_predecessors(PredEdgeMap pa, EventTag);
----

== Template Parameters

[cols="1,3",options="header"]
|===
| Parameter | Description

| `PredEdgeMap`
| A WritablePropertyMap whose key type is the graph's vertex descriptor and whose
  value type is the graph's edge descriptor.

| `EventTag`
| The event at which to record. Must be an edge event (e.g. `on_tree_edge`,
  `on_relax_edge`).
|===

== Associated Types

[cols="1,3",options="header"]
|===
| Type | Description

| `event_filter`
| The event tag the visitor responds to. Same type as `EventTag`.
|===

== Member Functions

[cols="1,3",options="header"]
|===
| Member | Description

| `edge_predecessor_recorder(PredEdgeMap pa)`
| Constructs a recorder writing predecessor edges into the property map `pa`.

| `void operator()(Edge e, const Graph& g)`
| Given edge `e = (u, v)`, records `e` as the predecessor edge of `v`:
  `put(pa, v, e)`.
|===

== Non-Member Functions

[cols="1,3",options="header"]
|===
| Function | Description

| `record_edge_predecessors(PredEdgeMap pa, EventTag)`
| Convenience factory that creates an `edge_predecessor_recorder`.
|===

TIP: The source vertex (the root of the search tree) is not assigned a predecessor
edge. Initialize it to a sentinel value before running the algorithm to identify
the root. For DFS (which builds a forest), do the same for every vertex so all
roots can be distinguished.

== Example

[source,cpp]
----
include::example$visitors/edge_predecessor_recorder.cpp[]
----

[,text]
----
include::example$visitors/edge_predecessor_recorder.txt[]
----
