are*_*lek 7 c++ boost boost-graph argument-dependent-lookup
考虑这段代码(或实例):
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/range/iterator_range.hpp>
using std::cout;
int main() {
boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> g;
add_edge(0, 1, g);
add_edge(1, 2, g);
for(auto v : make_iterator_range(vertices(g))) {
cout << v << " has " << degree(v, g) << " neighbor(s): ";
for(auto w : make_iterator_range(adjacent_vertices(v, g))) cout << w << ' ';
cout << '\n';
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么功能add_edge
,make_iterator_range
,vertices
,degree
和adjacent_vertices
那来自无Boost库工作boost::
空间前缀?
对我来说最令人费解的是,根据具体情况,有时需要前缀.下面是一个示例,当使用不同的图形结构时,会产生可以通过前缀修复的编译错误boost::make_iterator_range
.
我看了一下BGL文档,但没有找到任何关于这个问题的内容.是我的错还是一些BGL标题污染全局命名空间?这是设计还是这个错误?
它与boost
任何namespace
.
使用参数相关查找(ADL),参数中的命名空间被添加到重载搜索中。
例如:
add_edge(0, 1, g);
Run Code Online (Sandbox Code Playgroud)
g
来自 namespace boost
,所以我们add_edge
也在 namespace 中寻找boost
。
归档时间: |
|
查看次数: |
306 次 |
最近记录: |