c++ - 为什么boost需要&vector[0]?

标签 c++ boost

edmonds_maximum_cardinality_matching例如。我能做到:

  vector<uint32_t> mate_map(n_vertices);
  edmonds_maximum_cardinality_matching(g, &mate_map[0]);

但不是:

  vector<uint32_t> mate_map(n_vertices);
  edmonds_maximum_cardinality_matching(g, mate_map);

为什么会这样? vector 具有数组具有的所有操作,对吗?注意:这是我无法真正处理的错误消息(针对第二个片段):

In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp: In instantiation of ‘static void boost::extra_greedy_matching<Graph, MateMap>::find_matching(const Graph&, MateMap) [with Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>; MateMap = std::vector<unsigned int>]’:
/usr/include/boost/graph/max_cardinality_matching.hpp:842:63:   required from ‘bool boost::matching(const Graph&, MateMap, VertexIndexMap) [with Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>; MateMap = std::vector<unsigned int>; VertexIndexMap = boost::vec_adj_list_vertex_id_map<boost::no_property, long unsigned int>; AugmentingPathFinder = boost::edmonds_augmenting_path_finder; InitialMatchingFinder = boost::extra_greedy_matching; MatchingVerifier = boost::no_matching_verifier]’
/usr/include/boost/graph/max_cardinality_matching.hpp:885:19:   required from ‘void boost::edmonds_maximum_cardinality_matching(const Graph&, MateMap, VertexIndexMap) [with Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>; MateMap = std::vector<unsigned int>; VertexIndexMap = boost::vec_adj_list_vertex_id_map<boost::no_property, long unsigned int>]’
/usr/include/boost/graph/max_cardinality_matching.hpp:894:70:   required from ‘void boost::edmonds_maximum_cardinality_matching(const Graph&, MateMap) [with Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>; MateMap = std::vector<unsigned int>]’
main.C:20:51:   required from here
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: error: no matching function for call to ‘put(std::vector<unsigned int>&, boost::iterators::detail::iterator_facade_base<boost::range_detail::integer_iterator<long unsigned int>, long unsigned int, boost::iterators::random_access_traversal_tag, long unsigned int, long int, false, false>::reference, boost::graph_traits<boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS> >::vertex_descriptor)’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note: candidates are:
In file included from /usr/include/boost/graph/adjacency_list.hpp:36:0,
                 from main.C:4:
/usr/include/boost/property_map/property_map.hpp:124:15: note: template<class T, class V> void put(T*, std::ptrdiff_t, const V&)
   inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val;  }
               ^
/usr/include/boost/property_map/property_map.hpp:124:15: note:   template argument deduction/substitution failed:
In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note:   mismatched types ‘T*’ and ‘std::vector<unsigned int>’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^
In file included from /usr/include/boost/graph/adjacency_list.hpp:36:0,
                 from main.C:4:
/usr/include/boost/property_map/property_map.hpp:193:8: note: template<class K, class V> void boost::put(const boost::writable_property_map_archetype<K, V>&, const typename boost::writable_property_map_archetype<K, V>::key_type&, const typename boost::writable_property_map_archetype<K, V>::value_type&)
   void put(const writable_property_map_archetype<K,V>&,
        ^
/usr/include/boost/property_map/property_map.hpp:193:8: note:   template argument deduction/substitution failed:
In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note:   ‘std::vector<unsigned int>’ is not derived from ‘const boost::writable_property_map_archetype<K, V>’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^
In file included from /usr/include/boost/graph/adjacency_list.hpp:36:0,
                 from main.C:4:
/usr/include/boost/property_map/property_map.hpp:307:3: note: template<class PropertyMap, class Reference, class K, class V> void boost::put(const boost::put_get_helper<Reference, PropertyMap>&, K, const V&)
   put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
   ^
/usr/include/boost/property_map/property_map.hpp:307:3: note:   template argument deduction/substitution failed:
In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note:   ‘std::vector<unsigned int>’ is not derived from ‘const boost::put_get_helper<Reference, PropertyMap>’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^
In file included from /usr/include/boost/graph/properties.hpp:21:0,
                 from /usr/include/boost/graph/adjacency_list.hpp:44,
                 from main.C:4:
/usr/include/boost/graph/property_maps/null_property_map.hpp:32:10: note: template<class K, class V> void boost::put(boost::null_property_map<K, V>&, const K&, const V&)
     void put(null_property_map<K,V>& /*pm*/, const K& /*key*/, const V& /*value*/)
          ^
/usr/include/boost/graph/property_maps/null_property_map.hpp:32:10: note:   template argument deduction/substitution failed:
In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note:   ‘std::vector<unsigned int>’ is not derived from ‘boost::null_property_map<K, V>’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^
In file included from /usr/include/boost/graph/adjacency_list.hpp:246:0,
                 from main.C:4:
/usr/include/boost/graph/detail/adjacency_list.hpp:1760:5: note: template<class Config, class Base, class Property, class Key, class Value> void boost::put(Property, boost::adj_list_helper<Config, Base>&, const Key&, const Value&)
     put(Property p, adj_list_helper<Config, Base>& g,
     ^
/usr/include/boost/graph/detail/adjacency_list.hpp:1760:5: note:   template argument deduction/substitution failed:
In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note:   mismatched types ‘boost::adj_list_helper<Config, Base>’ and ‘boost::iterators::detail::iterator_facade_base<boost::range_detail::integer_iterator<long unsigned int>, long unsigned int, boost::iterators::random_access_traversal_tag, long unsigned int, long int, false, false>::reference {aka long unsigned int}’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^
In file included from /usr/include/boost/graph/max_cardinality_matching.hpp:22:0,
                 from main.C:5:
/usr/include/boost/graph/filtered_graph.hpp:472:3: note: template<class G, class EP, class VP, class Property, class Key, class Value> void boost::put(Property, const boost::filtered_graph<Graph, EdgePredicate, VertexPredicate>&, const Key&, const Value&)
   put(Property p, const filtered_graph<G, EP, VP>& g, const Key& k,
   ^
/usr/include/boost/graph/filtered_graph.hpp:472:3: note:   template argument deduction/substitution failed:
In file included from main.C:5:0:
/usr/include/boost/graph/max_cardinality_matching.hpp:617:58: note:   mismatched types ‘const boost::filtered_graph<Graph, EdgePredicate, VertexPredicate>’ and ‘boost::iterators::detail::iterator_facade_base<boost::range_detail::integer_iterator<long unsigned int>, long unsigned int, boost::iterators::random_access_traversal_tag, long unsigned int, long int, false, false>::reference {aka long unsigned int}’
         put(mate, *vi, graph_traits<Graph>::null_vertex());
                                                          ^

完整输出在这里:http://pastebin.com/fG2aLRiG (由于SO对帖子长度的限制而外包)

最佳答案

“vector 具有数组的所有操作”不。数组隐式衰减为指针, vector 不会。因此,当 boost 尝试将其传递给 put 时它生成此错误的函数:

error: no matching function for call to ‘put(std::vector<unsigned int>&, [blah blah])
note: candidates are:

template<class T, class V> void put(T*, std::ptrdiff_t, const V&)
template argument deduction/substitution failed: 
mismatched types ‘T*’ and ‘std::vector<unsigned int>’

[followed by details about the other potential put functions]

显然是 put函数将接受其中之一,或隐式转换为其中之一的东西。

  • T*
  • boost::writable_property_map_archetype<K, V>&
  • const boost::put_get_helper<Reference, PropertyMap>&
  • boost::null_property_map<K, V>&
  • Property

(edmonds_maximum_cardinality_matching 可能有导致这些其他类型也无效的其他要求,我只是说这五种类型通过了这个特定的障碍。)

关于c++ - 为什么boost需要&vector[0]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27827391/

相关文章:

c++ - 具有 std::vector 和 std::set 属性的容器?

c++ - 分析多线程代码,采样如何工作

c++ - 在类中使用枚举时,它会是公开的吗?为什么?

c++ - 从 std::vector 中删除前 N 个元素

python - Boost::Python,将元组转换为 Python 有效,vector<tuple> 无效

c++ - QT : Passing QString to QThread

c++ - ACE(C++ 库)是否仍用于高性能计算?

c++ - 如何在 C++ 中进行 regex_match #(哈希符号)?

c++ - boost zip 迭代器和 std::sort

c++ - CMake 链接以 boost 。错误 LNK2005