Graphle 1.0.0
A C++20 header-only graph library
Loading...
Searching...
No Matches
graph.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <common.hpp>
4#include <meta/concepts.hpp>
5#include <meta/value.hpp>
9
10#include <ranges>
11#include <concepts>
12#include <utility>
13
14
15namespace graphle {
42 template <
43 typename Vertex,
44 meta::value_wrapper_of<bool> IsDirected = std::true_type,
45 maybe_vertex_getter<Vertex> GetVertices = meta::none,
46 maybe_edge_getter<Vertex> GetEdges = meta::none,
47 maybe_vertex_edge_getter<Vertex> GetOutEdges = meta::none,
48 maybe_vertex_edge_getter<Vertex> GetInEdges = meta::none,
49 graph_compare_traits<Vertex> CompareAs = compare_by_address<Vertex>,
50 typename Error = decltype(detail::graph_constraints_check<Vertex, IsDirected, GetVertices, GetEdges, GetOutEdges, GetInEdges>())
51 > struct graph {
52 using vertex_type = Vertex*;
54
55
56 constexpr static inline bool is_directed = IsDirected::value;
57 constexpr static inline bool has_vertex_list = !meta::is_none_v<GetVertices>;
58 constexpr static inline bool has_edge_list = !meta::is_none_v<GetEdges>;
59 constexpr static inline bool has_out_edges = !meta::is_none_v<GetOutEdges>;
60 constexpr static inline bool has_in_edges = !meta::is_none_v<GetInEdges>;
61
62 using get_vertices_t = GetVertices;
63 using get_edges_t = GetEdges;
64 using get_out_edges_t = GetOutEdges;
65 using get_in_edges_t = GetInEdges;
66 using vertex_compare_t = typename CompareAs::vertex_compare;
67 using edge_compare_t = typename CompareAs::edge_compare;
68 using vertex_hash_t = typename CompareAs::vertex_hash;
69 using edge_hash_t = typename CompareAs::edge_hash;
70
71
72 // Required for template argument deduction. See README for more info.
76
77 // Note: can be initialized using aggregate initialization / designated initializers.
78 GetVertices get_vertices;
79 GetEdges get_edges;
80 GetOutEdges get_out_edges;
81 GetInEdges get_in_edges;
82 };
83
84
86 template <typename G> concept graph_type = meta::is_template_v<graph, G>;
88 template <typename G> concept graph_ref = graph_type<std::remove_cvref_t<G>>;
89
91 template <graph_ref G> using vertex_of = typename std::remove_cvref_t<G>::vertex_type;
93 template <graph_ref G> using edge_of = typename std::remove_cvref_t<G>::edge_type;
95 template <graph_ref G> using vertex_compare_of = typename std::remove_cvref_t<G>::vertex_compare_t;
97 template <graph_ref G> using edge_compare_of = typename std::remove_cvref_t<G>::edge_compare_t;
99 template <graph_ref G> using vertex_hash_of = typename std::remove_cvref_t<G>::vertex_hash_t;
101 template <graph_ref G> using edge_hash_of = typename std::remove_cvref_t<G>::edge_hash_t;
102
103
105 template <graph_ref G> constexpr inline bool graph_is_directed = std::remove_cvref_t<G>::is_directed;
107 template <graph_ref G> constexpr inline bool graph_has_vertex_list = std::remove_cvref_t<G>::has_vertex_list;
109 template <graph_ref G> constexpr inline bool graph_has_edge_list = std::remove_cvref_t<G>::has_edge_list;
111 template <graph_ref G> constexpr inline bool graph_has_out_edges = std::remove_cvref_t<G>::has_out_edges;
113 template <graph_ref G> constexpr inline bool graph_has_in_edges = std::remove_cvref_t<G>::has_in_edges;
114
116 template <typename G> concept directed_graph = graph_is_directed<G>;
118 template <typename G> concept non_directed_graph = !graph_is_directed<G>;
120 template <typename G> concept vertex_list_graph = graph_has_vertex_list<G>;
122 template <typename G> concept edge_list_graph = graph_has_edge_list<G>;
124 template <typename G> concept out_edges_graph = graph_has_out_edges<G>;
126 template <typename G> concept in_edges_graph = graph_has_in_edges<G>;
127
128
130 template <typename T> constexpr static inline bool is_vertex = std::is_pointer_v<T>;
132 template <typename T> constexpr static inline bool is_edge = meta::is_template_v<std::pair, T> && is_vertex<typename T::first_type> && is_vertex<typename T::second_type>;
133}
typename std::remove_cvref_t< G >::edge_type edge_of
Definition: graph.hpp:93
typename std::remove_cvref_t< G >::edge_hash_t edge_hash_of
Definition: graph.hpp:101
constexpr bool graph_has_in_edges
Definition: graph.hpp:113
constexpr bool graph_has_edge_list
Definition: graph.hpp:109
typename std::remove_cvref_t< G >::vertex_hash_t vertex_hash_of
Definition: graph.hpp:99
typename std::remove_cvref_t< G >::vertex_compare_t vertex_compare_of
Definition: graph.hpp:95
typename std::remove_cvref_t< G >::edge_compare_t edge_compare_of
Definition: graph.hpp:97
constexpr bool graph_is_directed
Definition: graph.hpp:105
constexpr bool graph_has_out_edges
Definition: graph.hpp:111
typename std::remove_cvref_t< G >::vertex_type vertex_of
Definition: graph.hpp:91
constexpr bool graph_has_vertex_list
Definition: graph.hpp:107
std::pair< V *, V * > edge_for
type< T > deduce_as_t
Definition: value.hpp:30
meta::deduce_as_t< Vertex > deduce_vertex_type
Definition: graph.hpp:73
GetVertices get_vertices
Definition: graph.hpp:78
meta::deduce_as_t< IsDirected > deduce_is_directed
Definition: graph.hpp:74
GetEdges get_edges_t
Definition: graph.hpp:63
GetVertices get_vertices_t
Definition: graph.hpp:62
GetOutEdges get_out_edges
Definition: graph.hpp:80
typename CompareAs::vertex_compare vertex_compare_t
Definition: graph.hpp:66
typename CompareAs::vertex_hash vertex_hash_t
Definition: graph.hpp:68
GetInEdges get_in_edges_t
Definition: graph.hpp:65
typename CompareAs::edge_hash edge_hash_t
Definition: graph.hpp:69
GetEdges get_edges
Definition: graph.hpp:79
GetOutEdges get_out_edges_t
Definition: graph.hpp:64
GetInEdges get_in_edges
Definition: graph.hpp:81
Vertex * vertex_type
Definition: graph.hpp:52
typename CompareAs::edge_compare edge_compare_t
Definition: graph.hpp:67
detail::edge_for< Vertex > edge_type
Definition: graph.hpp:53
meta::deduce_as_t< CompareAs > deduce_compare_as
Definition: graph.hpp:75