Reputation: 972
I am using a boost::graph
and I noticed that when I am just using std::cout << *ei
where ei
is an edges iterator obtained, for example, from boost::edges
command, I see that something like "(x, y)" is printed, where x and y are integers. I assume that these numbers represent vertices descriptors.
According to this, I have some questions:
vertex_descriptor
representation in boost::graph
is int?operator<<
for edge_descriptor
is defined inside boost to make the output look like I described above? Otherwise, I cannot understand how it works in this way. Thanks
Upvotes: 1
Views: 954
Reputation: 392911
Q. does the default type for vertex_descriptor representation in boost::graph is int?
boost::graph
is not a type.
Many graph types exist (BGL is a generic template library).
The actual type of vertex_descriptor is opaque, and can be integral. E.g. it is integral¹ with vecS
vertex container selection in the adjacecy_list
template argument list.
Q. Is there any operator<< for edge_descriptor is defined inside boost to make the output look like I described above? Otherwise, I cannot understand how it works in this way.
Yes. For such a graph type, the following overload of operator<<
is injected into namespace std
(see boost/graph/detail/edge.hpp
):
namespace std {
template <class Char, class Traits, class D, class V>
std::basic_ostream<Char, Traits>&
operator<<(std::basic_ostream<Char, Traits>& os,
const boost::detail::edge_desc_impl<D,V>& e)
{
return os << "(" << e.m_source << "," << e.m_target << ")";
}
}
¹ Note that it's likely size_t
, not int
Upvotes: 1