property_put :: Boost.Graph Documentation

# property_put

Writes a fixed value to a property map when a vertex or edge is visited at an event point. Useful as an alternative to an explicit loop for initializing a property map, or to mark a subset of vertices or edges (for example, only back edges) during a search.

Defined in: `<boost/graph/visitors.hpp>`
Models: EventVisitor
Typical event: any (vertex or edge)

To use it, wrap it in an algorithm adaptor and optionally combine it with other event visitors; see the visitors overview.

## Synopsis

    template <typename PropertyMap, typename EventTag>
    struct property_put {
      typedef EventTag event_filter;
      property_put(PropertyMap pa,
                   typename property_traits<PropertyMap>::value_type value);

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

    template <typename PropertyMap, typename EventTag>
    property_put<PropertyMap, EventTag>
    put_property(PropertyMap pa,
                 typename property_traits<PropertyMap>::value_type value,
                 EventTag);

## Template Parameters

Parameter | Description
--- | ---
`PropertyMap` | A WritablePropertyMap whose key type is the graph’s vertex or edge descriptor (depending on the event tag).
`EventTag` | The event at which to write. May be any event, vertex or edge.

## Associated Types

Type | Description
--- | ---
`event_filter` | The event tag the visitor responds to. Same type as `EventTag`.

## Member Functions

Member | Description
--- | ---
`property_put(PropertyMap pa, value_type value)` | Constructs a visitor that writes the fixed `value` into the property map `pa`.
`void operator()(VertexOrEdge x, const Graph& g)` | Writes the fixed value into the property map for `x` (a vertex or edge): `put(pa, x, value)`.

## Non-Member Functions

Function | Description
--- | ---
`put_property(PropertyMap pa, value_type value, EventTag)` | Convenience factory that creates a `property_put`.

## Example

    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/depth_first_search.hpp>
    #include <boost/graph/visitors.hpp>
    #include <boost/property_map/property_map.hpp>
    #include <iostream>
    #include <vector>

    int main() {
        using namespace boost;
        using Graph = adjacency_list<vecS, vecS, directedS,
            no_property, property<edge_index_t, int>>;
        using Edge = graph_traits<Graph>::edge_descriptor;

        Graph g(4);
        add_edge(0, 1, 0, g);
        add_edge(1, 2, 1, g);
        add_edge(2, 0, 2, g);  // creates a back edge
        add_edge(1, 3, 3, g);

        // Mark back edges with true using property_put
        std::vector<bool> is_back(num_edges(g), false);
        auto edge_id = get(edge_index, g);
        auto back_map = make_iterator_property_map(is_back.begin(), edge_id);

        auto vis = make_dfs_visitor(
            put_property(back_map, true, on_back_edge())
        );
        depth_first_search(g, visitor(vis));

        for (auto ei = edges(g).first; ei != edges(g).second; ++ei) {
            Edge e = *ei;
            std::cout << source(e, g) << " -> " << target(e, g);
            if (is_back[get(edge_id, e)]) {
                std::cout << "  [back edge]";
            }
            std::cout << "\n";
        }
    }

    0 -> 1
    1 -> 2
    1 -> 3
    2 -> 0  [back edge]