Graphle 1.0.0
A C++20 header-only graph library
Loading...
Searching...
No Matches
edge_from_vertex.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <common.hpp>
4#include <graph/graph.hpp>
6
7#include <utility>
8
9
10namespace graphle {
11 namespace detail {
12 template <rng::input_range R, typename ProjectBound, typename ProjectRange> requires (rng::view<R> && is_vertex<rng::range_value_t<R>>)
14 public:
15 using vertex_type = typename rng::range_value_t<R>;
16 using edge_type = std::pair<vertex_type, vertex_type>;
17
29 constexpr edge_from_vertex_view(R base_range, vertex_type bind_vertex) :
30 base_range(std::move(base_range)),
31 bind_vertex(bind_vertex)
32 {}
33
34 [[nodiscard]] constexpr auto begin(void) const { return iterator { rng::begin(base_range), bind_vertex }; }
35 [[nodiscard]] constexpr auto end (void) const { return iterator { rng::end(base_range), bind_vertex }; }
36
37 [[nodiscard]] constexpr auto size(void) const requires rng::sized_range<const R> {
38 return rng::size(base_range);
39 }
40 private:
41 R base_range;
42 vertex_type bind_vertex;
43
44
45 class iterator : public transforming_wrapping_iterator<iterator, detail::const_iterator_t<R>, edge_type> {
46 public:
48
49 constexpr iterator(void) = default;
50 constexpr iterator(detail::const_iterator_t<R> base_iterator, vertex_type bind_vertex) : base(std::move(base_iterator)), bind_vertex(bind_vertex) {}
51 private:
52 friend class wrapping_iterator<iterator, detail::const_iterator_t<R>, edge_type>;
53
54
55 vertex_type bind_vertex;
56
57
58 constexpr auto get(void) const {
59 auto* provided_vertex = *base::wrapped_iterator;
60
61 edge_type result;
62 ProjectBound{}(result) = bind_vertex;
63 ProjectRange{}(result) = provided_vertex;
64
65 return result;
66 }
67 };
68 };
69 }
70
71
72 namespace views {
77 constexpr inline auto edge_from = detail::range_adaptor<
81 > {};
82
87 constexpr inline auto edge_to = detail::range_adaptor<
91 > {};
92 }
93}
94
95
constexpr edge_from_vertex_view(R base_range, vertex_type bind_vertex)
std::pair< vertex_type, vertex_type > edge_type
typename rng::range_value_t< R > vertex_type
constexpr auto edge_from
constexpr auto edge_to
decltype(rng::cbegin(std::declval< R & >())) const_iterator_t
Definition: range_utils.hpp:19