Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions include/graph/algorithm/traversal_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class VF, class G>
concept vertex_property_fn_for =
std::invocable<VF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&> &&
std::is_lvalue_reference_v<
std::invoke_result_t<VF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;

/// Type alias: extracts the value type from a vertex property function's return type
template <class VF, class G>
using vertex_fn_value_t = std::remove_cvref_t<
std::invoke_result_t<VF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;

//
// Distance and predecessor function concepts
//
Expand All @@ -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 <class DF, class G>
using distance_fn_value_t = std::remove_cvref_t<
std::invoke_result_t<DF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;
concept distance_fn_for = vertex_property_fn_for<DF, G>;

/// 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 <class DF, class G>
concept distance_fn_for =
std::invocable<DF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&> &&
std::is_lvalue_reference_v<
std::invoke_result_t<DF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;
using distance_fn_value_t = vertex_fn_value_t<DF, G>;

/// 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 <class PF, class G>
concept predecessor_fn_for =
std::invocable<PF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&> &&
std::is_lvalue_reference_v<
std::invoke_result_t<PF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;
concept predecessor_fn_for = vertex_property_fn_for<PF, G>;

/// 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 <class VF, class G>
concept vertex_property_fn_for =
std::invocable<VF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&> &&
std::is_lvalue_reference_v<
std::invoke_result_t<VF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;

/// Type alias: extracts the value type from a vertex property function's return type
template <class VF, class G>
using vertex_fn_value_t = std::remove_cvref_t<
std::invoke_result_t<VF&, const std::remove_reference_t<G>&, const vertex_id_t<G>&>>;
template <class PF, class G>
using predecessor_fn_value_t = vertex_fn_value_t<PF, G>;

/// Null predecessor function — used when predecessor tracking is not needed.
/// Detected at compile time via is_null_predecessor_fn_v to skip predecessor writes.
Expand Down
Loading