【发布时间】:2018-11-26 23:22:21
【问题描述】:
我为boost::adjacency_list写了一个小包装:
template <typename T>
using VertexWithIndexProperty =
boost::property<boost::vertex_index_t, int, T>;
template <typename VertexProperty, typename EdgeProperty =
boost::no_property>
class MutableGraph : public boost::adjacency_list< boost::setS,
boost::listS, boost::undirectedS,
VertexWithIndexProperty<VertexProperty>, EdgeProperty> {
public:
using BoostBase =
boost::adjacency_list<boost::setS, boost::listS, boost::undirectedS,
VertexWithIndexProperty<VertexProperty>,
EdgeProperty>;
MutableGraph() {}
MutableGraph(std::size_t n) : BoostBase(n) {}
MutableGraph(const MutableGraph &rhs) : BoostBase(rhs) {}
MutableGraph &operator=(const MutableGraph &rhs) {
static_cast<BoostBase *>(this)->operator=(rhs);
return *this;
}
};
然后我按如下方式使用它:我以集合的形式收集一些 vertex_descriptors 以创建boost::filtered_graph:
`
using Graph = MutableGraph<boost::property<vertex_color_t, int>>;
Graph g;
std::set<int> C, H; //vertex_descriptors I collect
...
auto vertex_index_map = get(vertex_index, g);
std::function<bool(vertex_descriptor)> vertexes_filter =
[&vertex_index_map, &C, &H](vertex_descriptor v) {
auto index = vertex_index_map[v];
return C.find(index) != C.end() || H.find(index) != H.end();
};
boost::filtered_graph<Graph, boost::keep_all, decltype(crown_vertexes_filter)>
auxilary(g, boost::keep_all(), crown_vertexes_filter);
一切正常,但是当我尝试获取顶点的任何 property_map 时,例如:`
auto auxilary_vertex_index_map
= get(boost::vertex_index, auxilary);
我收到以下错误:
could not convert
boost::adj_list_vertex_property_map<boost::adjacency_list<boost::setS,
boost::listS, boost::undirectedS,
boost::property<boost::vertex_index_t, int,
boost::property<boost::vertex_color_t, int> >,
boost::no_property, boost::no_property, boost::listS>, int,
int&, boost::vertex_index_t>
to
boost::adj_list_vertex_property_map<MutableGraph<
boost::property<boost::vertex_color_t, int> >,
int,
int&,
boost::vertex_index_t>
我收到这个错误
template <typename G, typename EP, typename VP, typename Property>
typename property_map<G, Property>::type
get(Property p, filtered_graph<G, EP, VP>& g)
{
return get(p, const_cast<G&>(g.m_g));
}
在filtered_graph.hpp.
我不明白为什么会发生这种情况,无论是因为我的包装器还是因为我决定使用嵌套属性而不是捆绑属性。
提前致谢!
【问题讨论】:
-
我建议
MutableGraph不是您类型的最佳名称,因为它与 Boost Graph Library 中的概念名称重复。这在错误消息中充其量是令人困惑的。
标签: c++ boost boost-graph adjacency-list