|
| Example | What it demonstrates |
|---|---|
| Adapting a Third-Party Graph | Wrapping an existing type with CPO friend functions |
| CppCon 2021 | BFS, Dijkstra, path reconstruction on real-world graph data |
| CppCon 2022 | Range-of-ranges adaptor, Dijkstra, Graphviz output |
| PageRank | PageRank algorithm (placeholder) |
| Basic Usage | Minimal vertex/edge traversal |
| Dijkstra CLRS | Dijkstra example from CLRS textbook |
| MST Usage | Minimum spanning tree |
| BGL Adaptor | Using graph-v3 on Boost.Graph data structures |
Directory: examples/AdaptingThirdPartyGraph/
Demonstrates how to adapt an existing third-party graph container for use with graph-v3 without modifying the original type. You provide a small set of ADL-findable free functions in the type's namespace:
vertices(g)— vertex range (wrapped intovertex_descriptor_view)edges(g, u)— out-edge range for a vertex descriptortarget_id(g, uv)— target vertex ID from an edge descriptorfind_vertex(g, uid)— vertex descriptor from a vertex ID
Once these are defined, the type satisfies graph::adjacency_list<G> and works
with all views and algorithms.
Key concepts demonstrated:
- CPO friend-function pattern with SFINAE trailing return types
- Vertex descriptor vs. vertex reference distinction
- Optional
vertex_value/edge_valueoverrides
Build target: adapting_third_party_graph
Directory: examples/CppCon2021/
Four standalone programs from the CppCon 2021 presentation, refactored from graph-v2 to graph-v3. Each program is self-contained with its own graph data.
Basic graph construction and traversal using vertexlist and incidence views.
Shows structured bindings [uid, u] and [vid, uv].
Build target: cppcon21_graphs
The Kevin Bacon "six degrees of separation" problem. Uses BFS
(vertices_breadth_first_search) to find shortest paths in a social graph.
Build target: cppcon21_bacon
OSPF-style shortest-path routing. Runs dijkstra_shortest_paths on a
weighted network graph and reconstructs the shortest-path tree.
Build target: cppcon21_ospf
Builds an actor/movie bipartite graph from the IMDB dataset, then uses BFS to find paths between actors.
Build target: cppcon21_imdb
Supporting files:
graphs/— graph data headers (karate, ospf, spice, imdb)include/utilities.hpp— shared output helpers
Directory: examples/CppCon2022/
Germany routes graph demonstration from the CppCon 2022 presentation, refactored from graph-v2 to graph-v3.
Builds a Germany inter-city routes graph using a generic rr_adaptor (range-of-ranges
adaptor), traverses vertices and edges, then runs Dijkstra shortest paths twice:
- Segment count — unweighted (each edge costs 1)
- Kilometers — weighted by route distance
Prints the shortest-path tree and reconstructs the path to the farthest city.
Build target: cppcon22_germany_routes
A reusable generic adaptor that wraps any random-access range-of-ranges (e.g.
vector<list<route>>) plus an optional parallel vertex-value vector and exposes
the full graph-v3 CPO interface.
Key implementation details:
- Data members declared before friend function trailing-return-type declarations (C++ class scope rule: trailing return types only see members declared above)
vertex_valueusesdecltype(auto)without trailing return type- Template friend functions with SFINAE guards for
edges,target_id,edge_value find_vertexconstructs avertex_descriptor_view::iteratordirectly from asize_tindex
Three function templates that write Graphviz .gv files:
output_routes_graphviz— full graph viavertexlist+incidenceoutput_routes_graphviz_dfs— DFS tree viaedges_dfs
Uses vertex_value(g, u) for city names and edge_value(g, uv) for distances.
Directory: examples/PageRank/
Placeholder for a PageRank implementation. PageRank was removed from the standard algorithm list because there is no single universally-agreed implementation — convergence criteria, damping factor, and normalization vary across textbooks and production systems.
File: examples/basic_usage.cpp
Minimal example: constructs a vector<vector<int>> graph, iterates vertices and
edges using CPOs. Good starting point for understanding the descriptor model.
Build target: basic_usage
File: examples/dijkstra_clrs_example.cpp
Dijkstra's algorithm on the textbook graph from Introduction to Algorithms
(Cormen, Leiserson, Rivest, Stein). Demonstrates dijkstra_shortest_paths with
weight function, distance, and predecessor containers.
Build target: dijkstra_example
File: examples/mst_usage_example.cpp
Minimum spanning tree (Kruskal's algorithm) on a weighted graph. Shows
kruskal_minimum_spanning_tree with edge-value weight extraction.
Build target: mst_usage_example
File: examples/bgl_adaptor_example.cpp
Demonstrates using graph-v3 views and algorithms on Boost.Graph adjacency_list
via the BGL adaptor (graph::bgl::graph_adaptor). Shows property bridge
functions for mapping BGL property maps to graph-v3 value functions.
Build target: bgl_adaptor_example
All examples are built as part of the default CMake build:
cmake --preset linux-gcc-debug
cmake --build build/linux-gcc-debugTo build a specific example:
cmake --build build/linux-gcc-debug --target cppcon22_germany_routesExamples link against the graph3 library target and require no external
dependencies beyond the library itself (Boost is needed only for
bgl_adaptor_example).