[英]To initialize a filtered_graph object in constructor after graph is defined in BOOST GRAPH
我在初始化boost中的filter_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的構造函數中,我用自己的邏輯(例如,頂點數,邊數等)填充GraphG。 現在,我想在圖G(填充G之后)上創建一個過濾器FG (它是A類的成員 )。
我想要這個的原因是,此篩選后的圖形作為對其他類構造函數的引用傳遞。 這迫使我使FG成為類A的成員。(我可以在A本身的構造函數中創建過濾器圖的新實例,但不會達到將引用返回給FG的目的。)
我希望這很清楚。 請建議
您可以使代碼編譯並正常運行。 嘗試按如下所示重新組織構造函數:
// constructor for A
template < ..typename list >
A ( ... input iterators list... )
: G() //calls constructor for G
, EPred(...) //some constructor for predicate
, FG( boost::make_filtered_graph(G, EPred) ) //creates your filtered graph
{
// fill the graph G with some values passed in constructor argument list.
}
其余代碼可以保持不變。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.