Skip to content

Commit

Permalink
Merge pull request #118 from stdgraph/edge_id
Browse files Browse the repository at this point in the history
Remove edge_id(g,uv) and edge_id_t<G>
  • Loading branch information
pratzl authored Jun 26, 2024
2 parents 2e77c19 + abe35e3 commit 7fe2cf3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 108 deletions.
95 changes: 0 additions & 95 deletions include/graph/detail/graph_cpo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,101 +1333,6 @@ inline namespace _Cpos {
}


//
// edge_id(g,uv) -> edge_id_t<G>
// default = edge_id_t<G>(source_id(g,uv),target_id(g,uv))
//
// edge_id_t<G> = edge_descriptor<vertex_id_t<_G>, true, void, void>
//
template <class _G>
using edge_id_t = edge_descriptor<vertex_id_t<_G>, true, void, void>; // {source_id, target_id}

namespace _Edge_id {
# if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-1681199
void edge_id() = delete; // Block unqualified name lookup
# else // ^^^ no workaround / workaround vvv
void edge_id();
# endif // ^^^ workaround ^^^

template <class _G>
concept _Has_ref_member = requires(_G&& __g, edge_reference_t<_G> uv) {
{ uv.edge_id(__g) } -> convertible_to<edge_id_t<_G>>;
};
template <class _G>
concept _Has_ref_ADL = _Has_class_or_enum_type<_G> //
&& requires(_G&& __g, const edge_reference_t<_G>& uv) {
{ _Fake_copy_init(edge_id(__g, uv)) } -> convertible_to<edge_id_t<_G>>; // intentional ADL
};

template <class _G>
concept _Can_id_eval = _Has_class_or_enum_type<_G> //
&& requires(_G&& __g, edge_reference_t<_G> uv) {
{ _Fake_copy_init(edge_id_t<_G>{source_id(__g, uv), target_id(__g, uv)}) };
};
class _Cpo {
private:
enum class _St_ref { _None, _Member, _Non_member, _Auto_eval };

template <class _G>
[[nodiscard]] static consteval _Choice_t<_St_ref> _Choose_ref() noexcept {
static_assert(is_lvalue_reference_v<_G>);
if constexpr (_Has_ref_member<_G>) {
return {_St_ref::_Member, noexcept(_Fake_copy_init(declval<edge_reference_t<_G>>().edge_id(declval<_G>())))};
} else if constexpr (_Has_ref_ADL<_G>) {
return {_St_ref::_Non_member,
noexcept(_Fake_copy_init(edge_id(declval<_G>(), declval<edge_reference_t<_G>>())))}; // intentional ADL
} else if constexpr (_Can_id_eval<_G>) {
return {_St_ref::_Auto_eval,
noexcept(_Fake_copy_init(edge_id_t<_G>{source_id(declval<_G>(), declval<edge_reference_t<_G>>()),
target_id(declval<_G>(), declval<edge_reference_t<_G>>())}))};
} else {
return {_St_ref::_None};
}
}

template <class _G>
static constexpr _Choice_t<_St_ref> _Choice_ref = _Choose_ref<_G>();

public:
/**
* @brief The id of an edge, made from its source_id and target_id.
*
* Complexity: O(1)
*
* Default implementation:
* edge_descriptor<vertex_id_t<G>,true>{source_id(g,uv), target_id(g,uv)}
* given that source_id(g,uv) is defined.
*
* @tparam G The graph type.
* @param g A graph instance.
* @param uv An edge reference.
* @return An edge_descriptor with the source_id and target_id.
*/
template <class _G>
requires(_Choice_ref<_G&>._Strategy != _St_ref::_None)
[[nodiscard]] constexpr auto operator()(_G&& __g, edge_reference_t<_G> uv) const
noexcept(_Choice_ref<_G&>._No_throw) {
constexpr _St_ref _Strat_ref = _Choice_ref<_G&>._Strategy;

if constexpr (_Strat_ref == _St_ref::_Member) {
return uv.edge_id(__g);
} else if constexpr (_Strat_ref == _St_ref::_Non_member) {
return edge_id(__g, uv); // intentional ADL
} else if constexpr (_Strat_ref == _St_ref::_Auto_eval) {
return edge_id_t<_G>{source_id(__g, uv), target_id(__g, uv)};
} else {
static_assert(_Always_false<_G>,
"edge_id(g,uv) is not defined, or target_id(g,uv) and source_id(g,uv) are not defined");
}
}
};
} // namespace _Edge_id

inline namespace _Cpos {
inline constexpr _Edge_id::_Cpo edge_id;
}


//
// find_vertex_edge(g,u,vid) -> vertex_edge_iterator<G>
// default = find(edges(g,u), [](uv) {target_id(g,uv)==vid;}
Expand Down
4 changes: 0 additions & 4 deletions include/graph/edgelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
// source_id(e)
// target_id(e)
// edge_value(e)
// edge_id(e) (todo)
//
// Edge definitions supported without overrides
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -132,9 +131,6 @@ namespace edgelist {
template <basic_sourced_edgelist EL> // For exposition only
using edge_value_t = decltype(edge_value(declval<edge_t<edge_range_t<EL>>>()));

template <basic_sourced_edgelist EL> // For exposition only
using edge_id_t = decltype(edge_id(declval<edge_t<edge_range_t<EL>>>()));

template <basic_sourced_edgelist EL> // For exposition only
using vertex_id_t = decltype(source_id(declval<edge_t<edge_range_t<EL>>>()));

Expand Down
14 changes: 5 additions & 9 deletions include/graph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ concept basic_targeted_edge = requires(G&& g, edge_reference_t<G> uv) { target_i
template <class G> // For exposition only
concept basic_sourced_edge = requires(G&& g, edge_reference_t<G> uv) { source_id(g, uv); };

template <class G> // For exposition only
concept basic_sourced_targeted_edge = basic_targeted_edge<G> && //
basic_sourced_edge<G> && //
requires(G&& g, edge_reference_t<G> uv) { edge_id(g, uv); };
template <class G> // For exposition only
concept basic_sourced_targeted_edge = basic_targeted_edge<G> && basic_sourced_edge<G>;


/**
Expand All @@ -102,10 +100,8 @@ template <class G> // For exposition only
concept sourced_edge = basic_sourced_edge<G> && //
requires(G&& g, edge_reference_t<G> uv) { source(g, uv); };

template <class G> // For exposition only
concept sourced_targeted_edge = targeted_edge<G> && //
sourced_edge<G> && //
requires(G&& g, edge_reference_t<G> uv) { edge_id(g, uv); };
template <class G> // For exposition only
concept sourced_targeted_edge = targeted_edge<G> && sourced_edge<G>;


/**
Expand Down Expand Up @@ -380,7 +376,7 @@ concept has_contains_edge = requires(G&& g, vertex_id_t<G> uid, vertex_id_t<G> v
template <class G>
struct define_unordered_edge : public false_type {}; // specialized for graph container edge

template <class G> // For exposition only
template <class G> // For exposition only
concept unordered_edge = basic_sourced_edge<G> && define_unordered_edge<G>::value;

//
Expand Down

0 comments on commit 7fe2cf3

Please sign in to comment.