From f34879f8836663a5cdf79a915c191360df312c19 Mon Sep 17 00:00:00 2001 From: Phil Ratzloff Date: Sat, 11 Apr 2026 10:28:14 -0400 Subject: [PATCH] Simplify traversal_common.hpp by unifying property function concepts - Define vertex_property_fn_for and vertex_fn_value_t as the primary concept/alias for per-vertex callable properties - Redefine distance_fn_for and predecessor_fn_for in terms of vertex_property_fn_for to eliminate duplicated constraints - Redefine distance_fn_value_t in terms of vertex_fn_value_t to eliminate duplicated type extraction logic --- include/graph/algorithm/traversal_common.hpp | 47 +++++++++----------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/include/graph/algorithm/traversal_common.hpp b/include/graph/algorithm/traversal_common.hpp index 2d6c343..eba6a63 100644 --- a/include/graph/algorithm/traversal_common.hpp +++ b/include/graph/algorithm/traversal_common.hpp @@ -115,6 +115,20 @@ constexpr auto zero_distance() { return DistanceValue(); } +/// General concept: a callable returning a mutable lvalue reference to any per-vertex property value. +/// Used by connected_components, label_propagation, and similar algorithms with per-vertex +/// property output parameters. +template +concept vertex_property_fn_for = + std::invocable&, const vertex_id_t&> && + std::is_lvalue_reference_v< + std::invoke_result_t&, const vertex_id_t&>>; + +/// Type alias: extracts the value type from a vertex property function's return type +template +using vertex_fn_value_t = std::remove_cvref_t< + std::invoke_result_t&, const vertex_id_t&>>; + // // Distance and predecessor function concepts // @@ -124,38 +138,21 @@ constexpr auto zero_distance() { // or in an external container. // -/// Type alias: extracts the distance value type from a distance function's return type +/// Concept: a callable returning a mutable reference to a per-vertex distance value template -using distance_fn_value_t = std::remove_cvref_t< - std::invoke_result_t&, const vertex_id_t&>>; +concept distance_fn_for = vertex_property_fn_for; -/// Concept: a callable returning a mutable reference to a per-vertex distance value +/// Type alias: extracts the distance value type from a distance function's return type template -concept distance_fn_for = - std::invocable&, const vertex_id_t&> && - std::is_lvalue_reference_v< - std::invoke_result_t&, const vertex_id_t&>>; +using distance_fn_value_t = vertex_fn_value_t; +/// Type alias: extracts the predecessor value type from a predecessor function's return type /// Concept: a callable returning a mutable reference to a per-vertex predecessor value template -concept predecessor_fn_for = - std::invocable&, const vertex_id_t&> && - std::is_lvalue_reference_v< - std::invoke_result_t&, const vertex_id_t&>>; +concept predecessor_fn_for = vertex_property_fn_for; -/// General concept: a callable returning a mutable lvalue reference to any per-vertex property value. -/// Used by connected_components, label_propagation, and similar algorithms with per-vertex -/// property output parameters. -template -concept vertex_property_fn_for = - std::invocable&, const vertex_id_t&> && - std::is_lvalue_reference_v< - std::invoke_result_t&, const vertex_id_t&>>; - -/// Type alias: extracts the value type from a vertex property function's return type -template -using vertex_fn_value_t = std::remove_cvref_t< - std::invoke_result_t&, const vertex_id_t&>>; +template +using predecessor_fn_value_t = vertex_fn_value_t; /// Null predecessor function — used when predecessor tracking is not needed. /// Detected at compile time via is_null_predecessor_fn_v to skip predecessor writes.