【发布时间】:2014-07-21 05:21:13
【问题描述】:
我在执行以下操作时遇到了一些麻烦:在 boost 图中使用 boost::bind / std::bind。
//function object
template <typename graph_t>
struct my_functor {
public:
my_functor() { }
my_functor(graph_t& _G) : G(_G) { }
template <typename edge_t>
bool operator() (const edge_t& edge1, const edge_1& edge2) {
//do something with edge properties.
// return true or false as per condition
}
private:
graph_t& G;
};
//boost graph
Graph_t G; // add some edges /properties etc.
//store the edges in some container
edge_container_t edge_set; //edge_container_t is say a std::vector<edge_descriptor>
//now the code
my_functor<graph_t> func(G); //initialize a function
//I want to bind by function object here so that it accepts two edges in the operator()() of function
//object.
auto bind_func = std::bind(func, _1, _2); //_1, _2 should take edge1 and edge2 as arguments
for (const auto& edge1 : edge_set) {
for (const auto& edge2 : edge_set {
if (edge1 != edge2)
bool y = bind_func(edge1, edge2) // bind_func returns a bool
}
}
我在创建 bind_func 时在这里做错了,但我对文档有点困惑。 如果我想使用 boost::bind 怎么办?
请在这种情况下提供帮助。 我使用反复试验得到的一些错误: 1.占位符 _1 , _2 未在范围内声明(我确实包括它仍然存在 2. 如果我使用 boost::bind 代替 std::bind,它会给出一些解包错误。
【问题讨论】:
标签: c++ c++11 boost boost-graph