This documentation is being rewritten. If something looks off, please cross-check with the Boost 1.91.0 Boost.Graph docs and open an issue.

property_put

Assigns a fixed constant value to a property map entry when an event occurs. Useful for initialization or for marking specific edges (e.g. back edges).

Defined in: <boost/graph/visitors.hpp>
Models: EventVisitor
Typical event: any

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]

Synopsis

template <typename PropertyMap, typename EventTag>
struct property_put;

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

Parameters

Parameter Description

PropertyMap

WritablePropertyMap. Key type is vertex or edge descriptor.

EventTag

Any event tag (vertex or edge).

Behavior

Writes the fixed value to the property map: put(pa, x, val).