【发布时间】:2026-01-11 05:00:01
【问题描述】:
我有一个关于在 boost 中初始化 filters_graph 的查询。
这是我的代码,
// predicate
template <typename TGraph>
struct edge_predicate
{
bool operator()(const typename boost::graph_traits<TGraph>::edge_descriptor& v) const
{
return true //testing purpose
}
};
// class
class A{
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node_Info, Edge_Info > Graph_t;
typedef boost::filtered_graph < Graph_t , edge_predicate > FilteredGraphType_t;
// members
Graph G;
FilteredGraphType_t FG() ; // empty filter graph ???
// constructor for A
template < ..typename list >
A ( ... input iterators list... )
{
fill the graph G with some values passed in constructor argument list.
// predicate
edge_predicate< Graph_t > EPred;
//filtered_graph
FilteredGraphType_t FG( G, EPred); // I am passing on edge predicate.
}
};
// member function:
FilteredGraphType_t& get_filtered_graph()
{
return FG;
}
问题:
FG 是 A 类的成员,G 也是 A 的成员。最初 G 是空对象,我想 FG 也是,..
在 A 的构造函数中,我用我的逻辑(例如顶点数、边数等)填充图 G。 现在,我想在图 G 上创建一个过滤器 FG (它是 A 类的成员)(在 G 被填充之后)。
我想要这个的原因是这个过滤后的图是作为对其他类构造函数的引用传递的。这迫使我将 FG 设为 A 类的成员。(我可以在 A 本身的构造函数中创建过滤图的新实例,但它不会起到返回对 FG 的引用的目的。)
我希望它很清楚。请建议
【问题讨论】:
标签: c++ graph boost-graph