= time_stamper

Stamps a monotonically increasing time value onto a vertex or edge when an event
occurs. Commonly used to record the discover and finish times of vertices during
a graph search.

*Defined in:* `<boost/graph/visitors.hpp>` +
*Models:* xref:visitors/EventVisitor.adoc[EventVisitor] +
*Typical event:* any (vertex or edge), e.g. `on_discover_vertex`,
`on_finish_vertex`

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 TimeMap, typename TimeT, typename EventTag>
struct time_stamper {
  typedef EventTag event_filter;
  time_stamper(TimeMap pa, TimeT& t);

  template <class X, class Graph>
  void operator()(X x, const Graph& g);
};

template <typename TimeMap, typename TimeT, typename EventTag>
time_stamper<TimeMap, TimeT, EventTag>
stamp_times(TimeMap pa, TimeT& t, EventTag);
----

== Template Parameters

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

| `TimeMap`
| A WritablePropertyMap whose key type is the graph's vertex or edge descriptor
  (depending on the event tag), and whose value type accepts the time counter.

| `TimeT`
| The time-counter type. Passed by reference and incremented on each event, so a
  single counter can be shared across several `time_stamper` objects.

| `EventTag`
| The event at which to stamp the time. May be any event, vertex or 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

| `time_stamper(TimeMap pa, TimeT& t)`
| Constructs a time stamper writing into the property map `pa` and using the
  shared counter `t`.

| `void operator()(X x, const Graph& g)`
| Increments the counter and stamps the new value onto `x` (a vertex or edge):
  `put(pa, x, ++t)`.
|===

== Non-Member Functions

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

| `stamp_times(TimeMap pa, TimeT& t, EventTag)`
| Convenience factory that creates a `time_stamper`.
|===

== Example

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

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