Skip to content

Commit

Permalink
Merge pull request #110 from stdgraph/phil/edgelist
Browse files Browse the repository at this point in the history
Phil/edgelist
  • Loading branch information
pratzl authored May 27, 2024
2 parents 4306e91 + 266f59a commit 192ef8f
Show file tree
Hide file tree
Showing 5 changed files with 926 additions and 463 deletions.
109 changes: 4 additions & 105 deletions include/graph/detail/graph_cpo.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

// (included from graph.hpp)
#include "graph/graph_descriptors.hpp"
#include "tag_invoke.hpp"

#ifndef GRAPH_CPO_HPP
Expand Down Expand Up @@ -964,15 +965,6 @@ namespace _Target_id {
template <class _G>
concept _Is_tuple_id_adj = integral<tuple_element_t<0, _rr_edge_t<_G>>>; // vertex<vertex<tuple<int,...>>>

template <class _E>
concept _Has_edgl_ref_member = requires(_E&& e) {
{ _Fake_copy_init(e.target_id()) };
};
template <class _E>
concept _Has_edgl_ref_ADL = requires(_E&& __e) {
{ _Fake_copy_init(target_id(__e)) }; // intentional ADL
};

class _Cpo {
private:
enum class _St_ref { _None, _Member, _Non_member, _Basic_id, _Tuple_id, _Auto_eval };
Expand Down Expand Up @@ -1002,22 +994,6 @@ namespace _Target_id {
template <class _G>
static constexpr _Choice_t<_St_ref> _Choice_adjl_ref = _Choose_adjl_ref<_G>();

template <class _E>
[[nodiscard]] static consteval _Choice_t<_St_ref> _Choose_edgl_ref() noexcept {
static_assert(is_lvalue_reference_v<_E>);

if constexpr (_Has_edgl_ref_member<_E>) {
return {_St_ref::_Member, noexcept(_Fake_copy_init(declval<_E&>().target_id()))};
} else if constexpr (_Has_edgl_ref_ADL<_E>) {
return {_St_ref::_Non_member, noexcept(_Fake_copy_init(target_id(declval<_E>())))}; // intentional ADL
} else {
return {_St_ref::_None};
}
}

template <class _E>
static constexpr _Choice_t<_St_ref> _Choice_edgl_ref = _Choose_edgl_ref<_E>();

public:
/**
* @brief The target_id of an adjancy list edge
Expand Down Expand Up @@ -1051,32 +1027,6 @@ namespace _Target_id {
static_assert(_Always_false<_G>, "target_id(g,uv) or g.target_id(uv) is not defined");
}
}

/**
* @brief The target_id of an edgelist edge.
*
* Complexity: O(1)
*
* Default implementation:
*
* @tparam G The graph type.
* @param g A graph instance.
* @param uv An edge instance.
* @return The target_id on an edge for an ajacency_list
*/
template <class _E>
//requires(_Choice_edgl_ref<_G&>._Strategy != _St_ref::_None)
[[nodiscard]] constexpr auto operator()(_E&& __e) const noexcept(_Choice_edgl_ref<_E&>._No_throw) {
constexpr _St_ref _Strat_ref = _Choice_edgl_ref<_E&>._Strategy;

if constexpr (_Strat_ref == _St_ref::_Member) {
return __e.target_id();
} else if constexpr (_Strat_ref == _St_ref::_Non_member) {
return target_id(__e); // intentional ADL
} else {
static_assert(_Always_false<_E>, "target_id(e) or e.target_id() is not defined");
}
}
};
} // namespace _Target_id

Expand All @@ -1088,7 +1038,7 @@ inline namespace _Cpos {
//
// source_id(g,uv) -> vertex_id_t<G> (optional; only when a source_id exists on an edge)
//
namespace _EL_Source_id {
namespace _Source_id {
# if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-1681199
void source_id() = delete; // Block unqualified name lookup
# else // ^^^ no workaround / workaround vvv
Expand All @@ -1105,16 +1055,6 @@ namespace _EL_Source_id {
{ _Fake_copy_init(source_id(__g, uv)) }; // intentional ADL
};

template <class _E>
concept _Has_edgl_ref_member = requires(_E&& __e) {
{ _Fake_copy_init(__e.source_id()) };
};
template <class _E>
concept _Has_edgl_ref_ADL = _Has_class_or_enum_type<_E> //
&& requires(_E&& __e) {
{ _Fake_copy_init(source_id(__e)) }; // intentional ADL
};

class _Cpo {
private:
enum class _St_ref { _None, _Member, _Non_member, _Auto_eval };
Expand All @@ -1136,21 +1076,6 @@ namespace _EL_Source_id {
template <class _E>
static constexpr _Choice_t<_St_ref> _Choice_adjl_ref = _Choose_adjl_ref<_E>();

template <class _E>
[[nodiscard]] static consteval _Choice_t<_St_ref> _Choose_edgl_ref() noexcept {
static_assert(is_lvalue_reference_v<_E>);
if constexpr (_Has_edgl_ref_member<_E>) {
return {_St_ref::_Member, noexcept(_Fake_copy_init(declval<_E>().source_id()))};
} else if constexpr (_Has_edgl_ref_ADL<_E>) {
return {_St_ref::_Non_member, noexcept(_Fake_copy_init(source_id(declval<_E>())))}; // intentional ADL
} else {
return {_St_ref::_None};
}
}

template <class _E>
static constexpr _Choice_t<_St_ref> _Choice_edgl_ref = _Choose_edgl_ref<_E>();

public:
/**
* @brief The source_id of an adjacency list edge
Expand Down Expand Up @@ -1180,37 +1105,11 @@ namespace _EL_Source_id {
static_assert(_Always_false<_G>, "source_id(g,uv) or g.source_id(uv) is not defined");
}
}

/**
* @brief The source_id of an edgelist edge
*
* Complexity: O(1)
*
* Default implementation:
*
* @tparam E The edgelist value_type.
* @param e A edgelist edge instance.
* @return The source_id of the edge.
*/
template <class _E>
requires(_Choice_edgl_ref<_E&>._Strategy != _St_ref::_None)
[[nodiscard]] constexpr auto operator()(_E&& __e, edge_reference_t<_E> uv) const
noexcept(_Choice_edgl_ref<_E&>._No_throw) {
constexpr _St_ref _Strat_ref = _Choice_edgl_ref<_E&>._Strategy;

if constexpr (_Strat_ref == _St_ref::_Member) {
return __e.source_id();
} else if constexpr (_Strat_ref == _St_ref::_Non_member) {
return source_id(__e); // intentional ADL
} else {
static_assert(_Always_false<_E>, "source_id(e) or e.source_id() is not defined");
}
}
};
} // namespace _EL_Source_id
} // namespace _Source_id

inline namespace _Cpos {
inline constexpr _EL_Source_id::_Cpo source_id;
inline constexpr _Source_id::_Cpo source_id;
}


Expand Down
Loading

0 comments on commit 192ef8f

Please sign in to comment.