2015-01-07 40 views
1

edmonds_maximum_cardinality_matching。我可以這樣做:爲什麼助推需要&矢量[0]?例如

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); 

爲什麼會這樣呢?一個向量有一個數組有權的所有操作?注意:以下是錯誤消息(第二片段),我真的無法處理:

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

+0

「矢量」__不衰減到指向第一個元素的指針是一個_advantage_ over數組。數組衰減是可怕的,也是_never使用原始數組_的原因之一。 – bames53

回答

5

「一個向量具有一個數組具有的所有操作」否。數組隱式地衰減到指針,而不是向量。因此,當升壓嘗試將其傳遞給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] 

Apperently的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可能有其他要求,導致這些其他類型也是無效的,我只是說這五種類型通過這個特殊的障礙。)

1

不,std::vector(正因如此對樁的長度的限制外包) 不是是否具有所有這些操作,並且不會隱式轉換爲數組。忽略std::array不會改變這一點,出於您的目的,它會更適合。

+0

std :: array不會隱式地轉換爲數組(或指針) – Barry

+0

對不起,糟糕的表述。我的意思是std :: array在這種情況下通常會更好。 – Downvoter