property<Tag, T, NextProperty> :: Boost.Graph Documentation

# `property<Tag, T, NextProperty>`

The legacy way to attach interior properties to an `adjacency_list` or `adjacency_matrix`. A property is a (tag, value, rest) triple; the third parameter chains additional properties at the same attachment point (vertex, edge, or graph).

Defined in: `<boost/pending/property.hpp>`, re-exported via `<boost/graph/properties.hpp>`.

| For new code, prefer bundled properties — they are a regular struct and read far better. Use `property<>` when you need to interoperate with an algorithm that looks up a well-known tag (e.g. `edge_weight_t`), or when you are required to declare `vertex_index_t` explicitly (as with `listS` vertex storage).

## Synopsis

    namespace boost {

    template <class Tag, class T, class NextProperty = no_property>
    struct property : public NextProperty {
        typedef NextProperty next_type;
        typedef Tag          tag_type;
        typedef T            value_type;

        property();
        property(const T& v);
        property(const T& v, const NextProperty& b);

        T m_value;
    };

    } // namespace boost

Template parameter | Description | Default
--- | --- | ---
`Tag` | A property-tag type such as `edge_weight_t`. Uniquely names the property so algorithms can find it via `get(Tag(), g)`. |
`T` | The value type stored per vertex / edge / graph for this property. |
`NextProperty` | Another `property<…>` to chain at the same attachment point, or `no_property` for the tail of the chain. | `no_property`

## Example

    // Nested `property<>` declarations let you stack multiple interior
    // properties on a single kind (vertex, edge, or graph).
    //
    // New code should prefer bundled properties (structs) — see
    // property_maps/bundled. Nested property<> is still needed when you
    // want to coexist with algorithms that lookup a specific tag
    // (e.g. edge_weight_t) OR when you need to declare vertex_index_t
    // for a listS-based graph.

    #include <boost/graph/adjacency_list.hpp>
    #include <iostream>
    #include <string>

    using namespace boost;

    // Two edge properties: weight (int) nested inside a name (string).
    using EdgeProps =
        property<edge_weight_t, int,
        property<edge_name_t,   std::string>>;

    using Graph = adjacency_list<vecS, vecS, directedS, no_property, EdgeProps>;

    int main() {
        Graph g(3);
        // Values are supplied positionally, outermost tag first.
        add_edge(0, 1, EdgeProps(5, property<edge_name_t, std::string>("a->b")), g);
        add_edge(1, 2, EdgeProps(3, property<edge_name_t, std::string>("b->c")), g);

        auto w = get(edge_weight, g);
        auto n = get(edge_name,   g);

        for (auto e : make_iterator_range(edges(g))) {
            std::cout << get(n, e) << " weight=" << get(w, e) << '\n';
        }
    }

    a->b weight=5
    b->c weight=3

The outermost `property<>` is consumed first by `add_edge`. If you are chaining more than two properties, the syntax (and the compile errors) become bad enough that bundled properties are almost always the better choice.

## Predefined property tags

The tags below are declared in `<boost/graph/properties.hpp>`. Each tag `foo_t` is accompanied by a constant of that type spelled `foo` for use as a runtime argument to `get(foo, g)`.

### Vertex tags

Tag | Typical use
--- | ---
`vertex_index_t` | Integer index in `[0, num_vertices(g))`. Automatic for `vecS` vertex storage; you must declare and populate it yourself for `listS` / `setS`.
`vertex_name_t` | Vertex labels, usually `std::string`.
`vertex_color_t` | Traversal color used by BFS/DFS-based algorithms.
`vertex_distance_t` | Shortest-path distance from a source.
`vertex_predecessor_t` | Predecessor vertex in a shortest-path or spanning tree.
`vertex_degree_t` / `vertex_in_degree_t` / `vertex_out_degree_t` | Cached or externally-tracked degrees (rarely needed as an interior property).
`vertex_current_degree_t`, `vertex_priority_t` | Working maps for Sloan ordering.
`vertex_discover_time_t`, `vertex_finish_time_t` | DFS event timestamps.
`vertex_rank_t`, `vertex_root_t` | Disjoint-sets rank and parent maps.
`vertex_centrality_t` | Betweenness centrality values.
`vertex_lowpoint_t` | Biconnected-components lowpoint.
`vertex_potential_t` | Min-cost-flow dual variables.

### Edge tags

Tag | Typical use
--- | ---
`edge_weight_t` | Primary edge weight / length / cost.
`edge_index_t` | Edge index. Never automatic — you must declare it and assign values yourself inside `add_edge` if any algorithm needs an edge-index map.
`edge_name_t` | Edge label.
`edge_color_t` | Edge traversal colors.
`edge_capacity_t`, `edge_residual_capacity_t`, `edge_reverse_t`, `edge_flow_t` | Properties required by the max-flow and min-cost-flow families.
`edge_centrality_t` | Edge betweenness centrality (used by `bc_clustering`).
`edge_discover_time_t`, `edge_finished_t` | DFS / traversal markers.

### Graph tags

Tag | Typical use
--- | ---
`graph_name_t` | Stored with the graph (used by GraphViz / GraphML I/O).
`graph_visitor_t` | Visitor override used internally by some algorithms.

| The BGL also defines bundle tags (`vertex_bundle_t`, `edge_bundle_t`, `graph_bundle_t`), `*_all_t` (everything attached at that point), and `*_global_t` / `*_local_t` / `*_owner_t` for distributed graphs. You will rarely name these directly.

## Members

Member | Description
--- | ---
`next_type` | The `NextProperty` template parameter.
`tag_type` | The `Tag` template parameter.
`value_type` | The `T` template parameter.
`property()` | Default-constructs `m_value` and the base-class chain. Requires every `T` in the chain to be `DefaultConstructible`.
`property(const T& v)` | Sets `m_value` to `v`; defaults the rest.
`property(const T& v, const NextProperty& b)` | Sets `m_value` to `v` and copy-initializes the rest from `b`.

## See also

- Traits and Iterators overview

- Property Maps

- Bundled Properties — the modern alternative to nested `property<>` chains.

- Internal Tags (Legacy) — usage notes for declared tag-based properties.