1111namespace gl {
1212
1313template <
14- type_traits::c_instantiation_of<vertex_descriptor> VertexType,
1514 type_traits::c_edge_directional_tag DirectionalTag = directed_t ,
1615 type_traits::c_properties Properties = types::empty_properties>
1716class edge_descriptor final {
1817public:
19- using type = edge_descriptor<VertexType, DirectionalTag, Properties>;
20- using vertex_type = VertexType;
18+ using type = edge_descriptor<DirectionalTag, Properties>;
2119 using directional_tag = DirectionalTag;
2220 using properties_type = Properties;
2321 using properties_ref_type = std::conditional_t <
@@ -34,14 +32,14 @@ class edge_descriptor final {
3432 edge_descriptor (const edge_descriptor&) = delete ;
3533 edge_descriptor& operator =(const edge_descriptor&) = delete ;
3634
37- explicit edge_descriptor (const vertex_type first, const vertex_type& second)
38- : _vertices(std::move( first), std::move( second) ) {}
35+ explicit edge_descriptor (const types::id_type first, const types::id_type second)
36+ : _vertices(first, second) {}
3937
4038 explicit edge_descriptor (
41- const vertex_type first, const vertex_type second, properties_type properties
39+ const types::id_type first, const types::id_type second, properties_type properties
4240 )
4341 requires(not type_traits::is_default_properties_type_v<properties_type>)
44- : _vertices(std::move( first), std::move( second) ), _properties(properties) {}
42+ : _vertices(first, second), _properties(properties) {}
4543
4644 edge_descriptor (edge_descriptor&&) = default ;
4745 edge_descriptor& operator =(edge_descriptor&&) = default ;
@@ -59,68 +57,45 @@ class edge_descriptor final {
5957 // clang-format off
6058 // gl_attr_force_inline misplacement
6159
62- [[nodiscard]] gl_attr_force_inline
63- const types::homogeneous_pair<const vertex_type>& incident_vertices () const {
60+ [[nodiscard]] gl_attr_force_inline types::homogeneous_pair<const types::id_type> incident_vertices () const {
6461 return this ->_vertices ;
6562 }
6663
67- [[nodiscard]] gl_attr_force_inline const types::homogeneous_pair<types::id_type> incident_vertex_ids () const {
68- return std::make_pair (this ->_vertices .first .id (), this ->_vertices .second .id ());
69- }
70-
71- [[nodiscard]] gl_attr_force_inline const vertex_type& first () const {
64+ [[nodiscard]] gl_attr_force_inline const types::id_type first () const {
7265 return this ->_vertices .first ;
7366 }
7467
75- [[nodiscard]] gl_attr_force_inline const vertex_type& second () const {
68+ [[nodiscard]] gl_attr_force_inline const types::id_type second () const {
7669 return this ->_vertices .second ;
7770 }
7871
7972 // clang-format on
8073
8174 // returns the `other` vertex or throws error if the given vertex is not incident with the edge
82- [[nodiscard]] const vertex_type incident_vertex (const types::id_type vertex_id) const {
83- if (vertex_id == this ->_vertices .first . id () )
75+ [[nodiscard]] const types::id_type incident_vertex (const types::id_type vertex_id) const {
76+ if (vertex_id == this ->_vertices .first )
8477 return this ->_vertices .second ;
8578
86- if (vertex_id == this ->_vertices .second . id () )
79+ if (vertex_id == this ->_vertices .second )
8780 return this ->_vertices .first ;
8881
8982 throw std::invalid_argument (std::format (" Got invalid vertex id: {}" , vertex_id));
9083 }
9184
92- [[nodiscard]] const vertex_type incident_vertex (const vertex_type& vertex) const {
93- return this ->incident_vertex (vertex.id ());
94- }
95-
9685 [[nodiscard]] gl_attr_force_inline bool is_incident_with (const types::id_type vertex_id) const {
97- return vertex_id == this ->_vertices .first .id () or vertex_id == this ->_vertices .second .id ();
98- }
99-
100- [[nodiscard]] gl_attr_force_inline bool is_incident_with (const vertex_type& vertex) const {
101- return this ->is_incident_with (vertex.id ());
86+ return vertex_id == this ->_vertices .first or vertex_id == this ->_vertices .second ;
10287 }
10388
10489 // true if the given vertex is the `source` of the edge
10590 [[nodiscard]] gl_attr_force_inline bool is_incident_from (const types::id_type vertex_id) const {
10691 return directional_tag::is_incident_from (*this , vertex_id);
10792 }
10893
109- // true if the given vertex is the `source` of the edge
110- [[nodiscard]] gl_attr_force_inline bool is_incident_from (const vertex_type& vertex) const {
111- return this ->is_incident_from (vertex.id ());
112- }
113-
11494 // true if the given vertex is the `target` vertex of the edge
11595 [[nodiscard]] gl_attr_force_inline bool is_incident_to (const types::id_type vertex_id) const {
11696 return directional_tag::is_incident_to (*this , vertex_id);
11797 }
11898
119- // true if the given vertex is the `target` vertex of the edge
120- [[nodiscard]] gl_attr_force_inline bool is_incident_to (const vertex_type& vertex) const {
121- return this ->is_incident_to (vertex.id ());
122- }
123-
12499 [[nodiscard]] gl_attr_force_inline bool is_loop () const {
125100 return this ->_vertices .first == this ->_vertices .second ;
126101 }
@@ -135,75 +110,49 @@ class edge_descriptor final {
135110 }
136111
137112private:
138- class vertex_writer {
139- public:
140- vertex_writer (const vertex_type& vertex, bool within_context)
141- : _vertex_ref(vertex), _within_context(within_context) {}
142-
143- friend std::ostream& operator <<(std::ostream& os, const vertex_writer& vw) {
144- if (vw._within_context )
145- os << vw._vertex_ref .id ();
146- else
147- os << vw._vertex_ref ;
148- return os;
149- }
150-
151- private:
152- const vertex_type& _vertex_ref;
153- bool _within_context;
154- };
155-
156- void _write (std::ostream& os, bool within_context = false ) const {
113+ void _write (std::ostream& os) const {
157114 if constexpr (not type_traits::c_writable<properties_type>) {
158- this ->_write_no_properties (os, within_context );
115+ this ->_write_no_properties (os);
159116 return ;
160117 }
161118 else {
162119 if (not io::is_option_set (os, io::graph_option::with_edge_properties)) {
163- this ->_write_no_properties (os, within_context );
120+ this ->_write_no_properties (os);
164121 return ;
165122 }
166123
167124 if (io::is_option_set (os, io::graph_option::verbose)) {
168- os << " [first: " << vertex_writer (this ->first (), within_context)
169- << " , second: " << vertex_writer (this ->second (), within_context)
125+ os << " [first: " << this ->_vertices .first << " , second: " << this ->_vertices .second
170126 << " | properties: " << this ->_properties << " ]" ;
171127 }
172128 else {
173- os << " [" << vertex_writer (this ->first (), within_context) << " , "
174- << vertex_writer (this ->second (), within_context) << " | " << this ->_properties
175- << " ]" ;
129+ os << " [" << this ->_vertices .first << " , " << this ->_vertices .second << " | "
130+ << this ->_properties << " ]" ;
176131 }
177132 }
178133 }
179134
180- void _write_no_properties (std::ostream& os, bool within_context = false ) const {
135+ void _write_no_properties (std::ostream& os) const {
181136 if (io::is_option_set (os, io::graph_option::verbose))
182- os << " [first: " << vertex_writer ( this ->first (), within_context)
183- << " , second: " << vertex_writer ( this -> second (), within_context) << " ]" ;
137+ os << " [first: " << this ->_vertices . first << " , second: " << this -> _vertices . first
138+ << " ]" ;
184139 else
185- os << " [" << vertex_writer (this ->first (), within_context) << " , "
186- << vertex_writer (this ->second (), within_context) << " ]" ;
140+ os << " [" << this ->_vertices .first << " , " << this ->_vertices .second << " ]" ;
187141 }
188142
189- types::homogeneous_pair<const vertex_type > _vertices;
143+ types::homogeneous_pair<types::id_type > _vertices;
190144 [[no_unique_address]] mutable properties_type _properties{};
191145};
192146
193147template <
194- type_traits::c_instantiation_of<vertex_descriptor> VertexType,
195148 type_traits::c_edge_directional_tag DirectionalTag = directed_t ,
196149 type_traits::c_properties Properties = types::empty_properties>
197- using edge = edge_descriptor<VertexType, DirectionalTag, Properties>;
150+ using edge = edge_descriptor<DirectionalTag, Properties>;
198151
199- template <
200- type_traits::c_instantiation_of<vertex_descriptor> VertexType,
201- type_traits::c_properties Properties = types::empty_properties>
202- using directed_edge = edge_descriptor<VertexType, directed_t , Properties>;
152+ template <type_traits::c_properties Properties = types::empty_properties>
153+ using directed_edge = edge_descriptor<directed_t , Properties>;
203154
204- template <
205- type_traits::c_instantiation_of<vertex_descriptor> VertexType,
206- type_traits::c_properties Properties = types::empty_properties>
207- using undirected_edge = edge_descriptor<VertexType, undirected_t , Properties>;
155+ template <type_traits::c_properties Properties = types::empty_properties>
156+ using undirected_edge = edge_descriptor<undirected_t , Properties>;
208157
209158} // namespace gl
0 commit comments