= property_writer

Writes the property value of a vertex or edge to an output iterator when an event
occurs. Useful for debugging or logging during a graph traversal.

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

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 PropertyMap, typename OutputIterator, typename EventTag>
struct property_writer {
  typedef EventTag event_filter;
  property_writer(PropertyMap pa, OutputIterator out);

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

template <typename PropertyMap, typename OutputIterator, typename EventTag>
property_writer<PropertyMap, OutputIterator, EventTag>
write_property(PropertyMap pa, OutputIterator out, EventTag);
----

== Template Parameters

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

| `PropertyMap`
| A ReadablePropertyMap whose key type is the graph's vertex or edge descriptor
  (depending on the event tag), and whose value type is writable to the output
  iterator.

| `OutputIterator`
| The output iterator the property values are written to.

| `EventTag`
| The event at which to write. 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

| `property_writer(PropertyMap pa, OutputIterator out)`
| Constructs a writer reading from the property map `pa` and writing to `out`.

| `void operator()(T x, Graph& g)`
| Reads the property of `x` (a vertex or edge) and writes it to the output
  iterator: `*out++ = get(pa, x)`.
|===

== Non-Member Functions

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

| `write_property(PropertyMap pa, OutputIterator out, EventTag)`
| Convenience factory that creates a `property_writer`.
|===

== Example

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

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