我正在嘗試使用named_graph mixin,我有點困惑remove_vertex()應該如何工作。boost圖形庫:named_graph和remove_vertex
#include <iostream>
#include <string>
#include <boost/lexical_cast.hpp>
#include <boost/graph/adjacency_list.hpp>
struct vertex_info {
std::string name; // uses vertex_from_name<vertex_info>
vertex_info(const std::string &name_) : name(name_) { }
};
ostream& operator<<(ostream & os, const vertex_info &v)
{
os << v.name;
return os;
}
namespace boost { namespace graph {
template<typename Type>
struct vertex_name_extractor
{
typedef Type type;
typedef const std::string& result_type;
result_type operator()(const Type& v) const
{
return v.name;
}
};
template<>
struct internal_vertex_name<vertex_info>
{
typedef vertex_name_extractor<vertex_info> type;
};
template<>
struct internal_vertex_constructor<vertex_info>
{
typedef vertex_from_name<vertex_info> type;
};
} }
typedef adjacency_list< vecS, vecS, undirectedS, vertex_info, edge_info> graph_t;
namespace bg=boost::graph;
int main()
{
using namespace std;
graph_t g;
int i;
typedef graph_traits<graph_t>::vertex_descriptor vert;
for(i=0;i < 10;++i)
{
string t_name("Vertex");
vert V;
t_name += lexical_cast<string>(i);
V = add_vertex(t_name,g);
}
typedef graph_t::vertex_name_type name_t;
name_t s_temp("Vertex2");
optional<vert> V(
find_vertex(s_temp,g));
if(V) {
cout << "Found vertex:" << *V << '\n';
//remove_vertex(*V,g); // (1)
//remove_vertex(vertex(*V,g),g); // (2)
//remove_vertex(g[*V],g); // (3)
//remove_vertex(s_temp,g); // (4)
} else {
cout << "Vertex not found\n";
}
graph_traits<graph_t>::vertex_iterator v_i, v_end;
for(tie(v_i,v_end) = vertices(g); v_i != v_end; ++v_i)
{
cout << '\'' << g[*v_i] << '\'' << endl;;
}
}
當我嘗試使用(3)或(4),我得到了沒有匹配的函數調用錯誤 'remove_vertex(vertex_info &,graph_t &)'
adjacency_list.hpp:2211名考生: remove_vertex(typename graph_t :: vertex_descriptor,graph_t &)
但是,當我嘗試使用(1)或(2)時,從'long unsigned int'無效轉換爲'const char *'時出現錯誤。
error: initializing argument 1 of ‘std::basic_string<...'
boost/graph/named_graph.hpp:349
template<BGL_NAMED_GRAPH_PARAMS>
inline void BGL_NAMED_GRAPH::removing_vertex(Vertex vertex)
{
named_vertices.erase(vertex); //line 349
}