迭代提升反向图中的边缘
iterating over edges in boost reverse graph
我无法迭代反向邻接列表图中的边列表。 下面列出了最小的代码示例,其中包含相应的 clang 6/gcc 7.3 错误消息。 任何帮助将不胜感激!!
#include <boost/config.hpp>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/reverse_graph.hpp>
#include <boost/graph/graph_utility.hpp>
using namespace boost;
struct vertexinfo {
int index{12};
};
struct edgeinfo {
int index{10};
};
using Graph = adjacency_list < vecS, vecS, bidirectionalS ,vertexinfo,edgeinfo>;
using ReversedGraph = reverse_graph<Graph>;
int main(){
Graph graph(5);
auto e1 = add_edge(0, 2, graph);
graph[e1.first].index = 1;
auto e2 = add_edge(1, 1, graph);
graph[e2.first].index = 2;
auto e3 = add_edge(1, 3, graph);
graph[e3.first].index = 3;
auto e4 = add_edge(1, 4, graph);
graph[e4.first].index = 4;
auto e5 = add_edge(2, 1, graph);
graph[e5.first].index = 5;
auto e6 = add_edge(2, 3, graph);
graph[e6.first].index = 6;
auto e7 = add_edge(2, 4, graph);
graph[e7.first].index = 7;
auto e8 = add_edge(3, 1, graph);
graph[e8.first].index = 8;
auto e9 = add_edge(3, 4, graph);
graph[e9.first].index = 9;
auto e10 = add_edge(4, 0, graph);
graph[e10.first].index = 10;
auto e11 = add_edge(4, 1, graph);
graph[e11.first].index = 11;
ReversedGraph reversed_graph(graph);
std::cout << "original graph:" << std::endl;
print_graph(graph, get(vertex_index, graph));
std::cout << std::endl << "reversed graph:" << std::endl;
print_graph(reversed_graph, get(vertex_index, graph));
auto range = edges(reversed_graph);
std::for_each(range.first,range.second,[&](const auto& item){
std::cout << reversed_graph[item].index << 'n';
});
return EXIT_SUCCESS;
}
错误信息 在文件中包含自
prog.cc:9: /opt/wandbox/boost-1.67.0/clang-6.0.0/include/boost/graph/reverse_graph.hpp:149:14: error: binding value of type 'const boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertexinfo, edgeinfo, boost::no_property, boost::listS>::edge_bundled' (aka 'const edgeinfo') to reference to type 'typename graph::detail::bundled_result<adjacency_list<vecS, vecS, bidirectionalS, vertexinfo, edgeinfo, no_property, listS>, typename detail::get_underlying_descriptor_from_reverse_descriptor<reverse_graph_edge_descriptor<edge_desc_impl<bidirectional_tag, unsigned long> > >::type>::type' (aka 'edgeinfo') drops 'const' qualifier
{ return m_g[detail::get_underlying_descriptor_from_reverse_descriptor<Descriptor>::convert(x)]; }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prog.cc:61:22: note: in instantiation of function template specialization 'boost::reverse_graph<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertexinfo, edgeinfo, boost::no_property, boost::listS>, const boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertexinfo, edgeinfo, boost::no_property, boost::listS> &>::operator[]<boost::detail::reverse_graph_edge_descriptor<boost::detail::edge_desc_impl<boost::bidirectional_tag, unsigned long> > >' requested here
std::cout << reversed_graph[item].index << 'n';
^ prog.cc:60:10: note: in instantiation of function template specialization 'std::__1::for_each<boost::iterators::transform_iterator<boost::detail::reverse_graph_edge_descriptor_maker<boost::detail::edge_desc_impl<boost::bidirectional_tag, unsigned long> >, boost::detail::undirected_edge_iter<std::__1::__list_iterator<boost::list_edge<unsigned long, edgeinfo>, void *>, boost::detail::edge_desc_impl<boost::bidirectional_tag, unsigned long>, long>, boost::iterators::use_default, boost::iterators::use_default>, (lambda at prog.cc:60:44)>' requested here
std::for_each(range.first,range.second,[&](const auto& item){
在 Boost Graph 文档中,反向图形适配器 (reverse_graph( 的构造函数默认为 GraphReference 参数的 const BidirectionalGraph&。 我必须将其更改为BidirectionalGraph&才能成功编译代码!
//using ReversedGraph = reverse_graph<Graph>;
using ReversedGraph = reverse_graph<Graph,Graph&>;
相关文章:
- 使用std::multimap迭代器创建std::list
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++中带有List类的迭代器Segfault
- 迭代时从向量和内存中删除对象
- 如何在c++迭代器类型中包装std::chrono
- 带过滤器的现代迭代c++集合
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- C++矢量迭代
- 集合上的输出迭代器:assign和increment迭代器
- Boost Spirit,获取迭代器内部语义动作
- 擦除while循环中迭代的元素
- 实现一个在集合上迭代的模板函数
- 对于set上的循环-获取next元素迭代器
- 在向量内的向量上迭代
- 迭代提升反向图中的边缘
- 如何修复此边缘迭代器分配错误
- 柠檬图迭代边缘
- 在boost图lib中,如何在不迭代顶点的所有外边缘的情况下获得该顶点的特定外边缘
- 使用基于范围的for迭代图的边缘
- 在边缘上迭代并使用OpenMesh获得顶点