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_writer

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

Defined in: <boost/graph/visitors.hpp>
Models: EventVisitor
Typical event: on_discover_vertex, on_examine_edge

Example

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/visitors.hpp>
#include <iostream>
#include <iterator>

int main() {
    using namespace boost;
    using Graph = adjacency_list<vecS, vecS, undirectedS>;

    Graph g(5);
    add_edge(0, 1, g);
    add_edge(0, 2, g);
    add_edge(1, 3, g);
    add_edge(2, 4, g);

    // Print vertex indices as they are discovered
    std::ostream_iterator<int> out(std::cout, " ");
    auto vis = make_bfs_visitor(
        write_property(get(vertex_index, g), out, on_discover_vertex())
    );

    std::cout << "BFS discovery order: ";
    breadth_first_search(g, vertex(0, g), visitor(vis));
    std::cout << "\n";
}
BFS discovery order: 0 1 2 3 4

Synopsis

template <typename PropertyMap, typename OutputIterator, typename EventTag>
struct property_writer;

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

Parameters

Parameter Description

PropertyMap

ReadablePropertyMap. Key type is vertex or edge descriptor.

OutputIterator

Output iterator. The property’s value type must be writable to it.

EventTag

Any event tag (vertex or edge).

Behavior

Writes the property value to the output iterator: *out++ = get(pa, x).