[boost-users][graph] There is graph::null_vertex, but no "null_edge"!
Hello! There is graph::null_vertex, but no "null_edge". Atl east, I don't find it. How can I return such a "special" edge descriptor, to mark,for example, that edge is not found or something like that?
On Thu, 17 Feb 2011, al.zatv wrote:
Hello!
There is graph::null_vertex, but no "null_edge". Atl east, I don't find it. How can I return such a "special" edge descriptor, to mark,for example, that edge is not found or something like that?
It looks like you are correct. The BGL functions that can return
non-existent edges return iterators instead, in which case edges(g).end()
is a legitimate "null" return value. If you know the graph is non-empty,
you can also return std::pair
Jeremiah Willcock
There is graph::null_vertex, but no "null_edge".
It looks like you are correct. The BGL functions that can return non-existent edges return iterators instead, in which case edges(g).end() is a legitimate "null" return value. If you know the graph is non-empty, you can also return std::pair
, returning make_pair(*edges(g).first, false) for the "not found" case and make_pair(..., true) otherwise.
Thank you for answer! I did it this way (for not founded edge) return make_pair( false, Graph::edge_descriptor() ); Am I correct? But, I think, it will be much better if null_edge will be added to the library. It can be -1 for vector containers and null for pointer-based descriptors, etc.
On Fri, 18 Feb 2011, al.zatv wrote:
Jeremiah Willcock
писал(а) в своём письме Fri, 18 Feb 2011 01:47:39 +0300: There is graph::null_vertex, but no "null_edge".
It looks like you are correct. The BGL functions that can return non-existent edges return iterators instead, in which case edges(g).end() is a legitimate "null" return value. If you know the graph is non-empty, you can also return std::pair
, returning make_pair(*edges(g).first, false) for the "not found" case and make_pair(..., true) otherwise. Thank you for answer! I did it this way (for not founded edge) return make_pair( false, Graph::edge_descriptor() );
Am I correct?
No, that won't work in general; I believe there are graph types whose edge_descriptors are not default constructible.
But, I think, it will be much better if null_edge will be added to the library. It can be -1 for vector containers and null for pointer-based descriptors, etc.
It would be, but that would be a change to base concepts that may cause old graph types to fail with new algorithms that use null_edge(). What does your code that may return a null edge descriptor do? Would it be possible to return an iterator instead? -- Jeremiah Willcock
Jeremiah Willcock
On Fri, 18 Feb 2011, al.zatv wrote:
Jeremiah Willcock
писал(а) в своём письме Fri, 18 Feb 2011 01:47:39 +0300: There is graph::null_vertex, but no "null_edge".
But, I think, it will be much better if null_edge will be added to the library. It can be -1 for vector containers and null for pointer-based descriptors, etc.
It would be, but that would be a change to base concepts that may cause old graph types to fail with new algorithms that use null_edge(). What does your code that may return a null edge descriptor do? Would it be possible to return an iterator instead?
My code just search one specific edge in graph. Actually, I think I can return an iterator. I just don't think about it. "Null edge-descriptor" was more natural idea for me:). So, looks like absence of null-edge is small "error-in-design" of library, or it was caused by some reason?
On Fri, 18 Feb 2011, al.zatv wrote:
Jeremiah Willcock
писал(а) в своём письме Fri, 18 Feb 2011 02:04:35 +0300: On Fri, 18 Feb 2011, al.zatv wrote:
Jeremiah Willcock
писал(а) в своём письме Fri, 18 Feb 2011 01:47:39 +0300: There is graph::null_vertex, but no "null_edge".
But, I think, it will be much better if null_edge will be added to the library. It can be -1 for vector containers and null for pointer-based descriptors, etc.
It would be, but that would be a change to base concepts that may cause old graph types to fail with new algorithms that use null_edge(). What does your code that may return a null edge descriptor do? Would it be possible to return an iterator instead?
My code just search one specific edge in graph. Actually, I think I can return an iterator. I just don't think about it. "Null edge-descriptor" was more natural idea for me:). So, looks like absence of null-edge is small "error-in-design" of library, or it was caused by some reason?
OK. I do not know if there was a reason; it is likely that nobody thought they would need it when designing the library. -- Jeremiah Willcock
participants (2)
-
al.zatv
-
Jeremiah Willcock