在boost库中未能使用property_map和comprateds_sparse_row_graph
failed to use property_map and compressed_sparse_row_graph in boost library
我已经阅读了提升文档,以找出如何使用property_map。
基于
// Property map accessors
template<typename PropertyTag>
property_map<compressed_sparse_row_graph, PropertyTag>::type
get(PropertyTag, compressed_sparse_row_graph& g)
我写了以下代码:
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <boost/utility.hpp>
typedef boost::compressed_sparse_row_graph<boost::bidirectionalS, boost::no_property, boost::property<boost::edge_weight_t, int> > AdjGraph;
typedef typename boost::property_map<AdjGraph, boost::edge_weight_t>::type WeightMap;
class data {
WeightMap weight;
data()
{
std::vector<std::pair<int, int> > edges;
std::vector<int> edgesAttr;
boost::shared_ptr<AdjGraph> adjGraph;
adjGraph = boost::shared_ptr<AdjGraph>(new AdjGraph(boost::edges_are_unsorted_multi_pass, edges.begin(), edges.end(), edgesAttr.begin(), 0));
weight = boost::get(boost::edge_weight, *adjGraph);
}
};
int main() { return 0; }
,但是当我尝试编译时发生了错误。
我修改了
weight = boost::get(boost::edge_weight, *adjGraph);
为
auto tmp = boost::get(boost::edge_weight, *adjGraph);
并且编译良好。
但是,AS" weight "不应该是静态变量," 自动权不可接受。
我想知道哪种类型" 权重"应该是。我尝试了" typeInfo "answers" typeid()。名称()",但输出不可读。
尽管我指的是1.61文档,但实际上我使用的是1.58 1.58文档
我想知道什么类型的"重量"应该是
类型是WeightMap
。您已经正确了。您正在解决错误的问题。这只是编译
WeightMap weight = boost::get(boost::edge_weight, *adjGraph);
那么什么是问题?
WeightMap
不可默认结构。像所有属性映射一样,这只是对实际数据的轻巧,低成本的"参考"(在图形模型中)。
因此,将其存储在成员中或将其共享给外界的理由零。
在更重要的层面上,因为属性映射通常是(肯定在这种情况下)引用了基础对象,因此,只要基础图是。
。因此,将重量图保留在成员中是没有意义的
活在Wandbox上
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/compressed_sparse_row_graph.hpp>
#include <boost/utility.hpp>
typedef boost::compressed_sparse_row_graph<boost::bidirectionalS, boost::no_property, boost::property<boost::edge_weight_t, int> > AdjGraph;
typedef typename boost::property_map<AdjGraph, boost::edge_weight_t>::type WeightMap;
class data {
boost::shared_ptr<AdjGraph> adjGraph;
WeightMap weight;
public:
data(std::vector<std::pair<int, int> > const& edges, std::vector<int> const& edgesAttr)
: adjGraph (boost::shared_ptr<AdjGraph>(new AdjGraph(boost::edges_are_unsorted_multi_pass, edges.begin(), edges.end(), edgesAttr.begin(), 0))),
weight(boost::get(boost::edge_weight, *adjGraph))
{
}
};
int main() {
std::vector<std::pair<int, int> > edges;
std::vector<int> edgesAttr;
data d(edges, edgesAttr);
}
解决了初始化 wigith的问题后,如果使用Boost 1.58和-STD = GNU 11:wandbox
In file included from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:28:0,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/detail/shared_count.hpp:396:33: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
explicit shared_count( std::auto_ptr<Y> & r ): pi_( new sp_counted_impl_p<Y>( r.get() ) )
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
In file included from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17:0,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:249:65: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
In file included from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17:0,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:448:31: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
In file included from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17:0,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:461:22: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
In file included from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17:0,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:538:34: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
shared_ptr & operator=( std::auto_ptr<Y> & r )
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
In file included from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17:0,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:547:34: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
shared_ptr & operator=( std::auto_ptr<Y> && r )
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
In file included from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17:0,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp: In member function 'boost::shared_ptr<T>& boost::shared_ptr<T>::operator=(std::auto_ptr<_Up>&&)':
/usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:549:38: warning: 'template<class> class std::auto_ptr' is deprecated [-Wdeprecated-declarations]
this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
^~~~~~~~
In file included from /usr/local/gcc-head/include/c++/7.0.0/memory:80:0,
from /usr/local/boost-1.59.0/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/boost-1.59.0/include/boost/smart_ptr/shared_ptr.hpp:23,
from /usr/local/boost-1.59.0/include/boost/shared_ptr.hpp:17,
from /usr/local/boost-1.59.0/include/boost/property_map/vector_property_map.hpp:14,
from /usr/local/boost-1.59.0/include/boost/property_map/property_map.hpp:600,
from /usr/local/boost-1.59.0/include/boost/graph/properties.hpp:19,
from /usr/local/boost-1.59.0/include/boost/graph/compressed_sparse_row_graph.hpp:26,
from prog.cc:2:
/usr/local/gcc-head/include/c++/7.0.0/bits/unique_ptr.h:51:28: note: declared here
template<typename> class auto_ptr;
^~~~~~~~
原因是 auto_ptr的弃用
要解决此问题,请使用Boost 1.60或更高版本,或用-STD = GNU 98。
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将重物插入std::map
- 使用通用值初始化 std::map,不重复
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- C++:当所有条目都保证是唯一时,替代 std::map
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 使用字符数组作为 Map 中的键
- C++如何创建 std::map
- C++ equivalent to Java Map getOrDefault?
- 从其他容器中移动构造"std::map"
- 如何使用 uint64_t 键类型从 std::map<int, std::string> 返回值?
- 将 std::map::emplace 与返回 shared_ptr 的函数一起使用是否正确?
- C++中 std::map 的运行时复杂度是多少?
- 为什么在 std::map 上移动无法将元素从一个映射移动到另一个映射