= distance_recorder

Records the distance of each vertex from the source vertex into a property map.
When applied to edge `e = (u, v)`, the distance of `v` is recorded as one more
than the distance of `u`.

*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 DistanceMap, typename EventTag>
struct distance_recorder {
  typedef EventTag event_filter;
  distance_recorder(DistanceMap pa);

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

template <typename DistanceMap, typename EventTag>
distance_recorder<DistanceMap, EventTag>
record_distances(DistanceMap pa, EventTag);
----

== Template Parameters

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

| `DistanceMap`
| A WritablePropertyMap whose key type is the graph's vertex descriptor and whose
  value type is the distance (a numeric type that supports adding one).

| `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

| `distance_recorder(DistanceMap pa)`
| Constructs a recorder writing distances into the property map `pa`.

| `void operator()(Edge e, const Graph& g)`
| Given edge `e = (u, v)`, records the distance of `v` as one more than the
  distance of `u`: `put(pa, v, get(pa, u) + 1)`.
|===

== Non-Member Functions

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

| `record_distances(DistanceMap pa, EventTag)`
| Convenience factory that creates a `distance_recorder`.
|===

== Example

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

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