Boost logo

Boost :

Subject: [boost] [BGL] boost::add_vertex - add unique vertexes to graph
From: Mariusz Kwiczala (mariusz.kwiczala_at_[hidden])
Date: 2009-06-23 07:14:46


Currently I externally check if vertex exist in graph.
But it is look like boost::add_vertex can check internally if vertexes
are unique.
      if (optional<vertex_descriptor> v
            = g.vertex_by_property(get_property_value(p, vertex_bundle)))
        return *v;

Could you send me any example where boost::add_vertex just return
already created vertex (line: "return *v") instead of create new one?

boost_1_39_0\boost\graph\detail\adjacency_list.hpp contain:
 template <class Graph, class Config, class Base>
    inline typename Config::vertex_descriptor
    add_vertex(const typename Config::vertex_property_type& p,
               vec_adj_list_impl<Graph, Config, Base>& g_) {
      typedef typename Config::vertex_descriptor vertex_descriptor;
      Graph& g = static_cast<Graph&>(g_);
      if (optional<vertex_descriptor> v
            = g.vertex_by_property(get_property_value(p, vertex_bundle)))
        return *v;
      typedef typename Config::stored_vertex stored_vertex;
      g.added_vertex(g.m_vertices.size() - 1);
      return g.m_vertices.size() - 1;

Best regards,

Boost list run by bdawes at, gregod at, cpdaniel at, john at