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 |
|---|---|---|
|
A property-tag type such as |
|
|
The value type stored per vertex / edge / graph for this property. |
|
|
Another |
|
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 |
|---|---|
|
Integer index in |
|
Vertex labels, usually |
|
Traversal color used by BFS/DFS-based algorithms. |
|
Shortest-path distance from a source. |
|
Predecessor vertex in a shortest-path or spanning tree. |
|
Cached or externally-tracked degrees (rarely needed as an interior property). |
|
Working maps for Sloan ordering. |
|
DFS event timestamps. |
|
Disjoint-sets rank and parent maps. |
|
Betweenness centrality values. |
|
Biconnected-components lowpoint. |
|
Min-cost-flow dual variables. |
Edge tags
| Tag | Typical use |
|---|---|
|
Primary edge weight / length / cost. |
|
Edge index. Never automatic — you must declare it and assign values
yourself inside |
|
Edge label. |
|
Edge traversal colors. |
|
Properties required by the max-flow and min-cost-flow families. |
|
Edge betweenness centrality (used by
|
|
DFS / traversal markers. |
Graph tags
| Tag | Typical use |
|---|---|
|
Stored with the graph (used by GraphViz / GraphML I/O). |
|
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 |
|---|---|
|
The |
|
The |
|
The |
|
Default-constructs |
|
Sets |
|
Sets |
See also
-
Bundled Properties — the modern alternative to nested
property<>chains. -
Internal Tags (Legacy) — usage notes for declared tag-based properties.