为什么boost需要&vector[0]?
Why does boost require &vector[0]?
以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);
为什么会这样?向量具有数组具有的所有操作,对吗?注意:这是我无法真正处理的错误消息(针对第二个片段):
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 对 post 长度的限制而外包)
不,std::vector
不 有所有这些操作,不会隐式转换为数组。忽略 std::array
不会改变的事实,为了您的目的,它会更适合。
"A vector has all operations an array has" 不。数组隐式衰减为指针,向量不会。因此,当 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
可能有其他要求导致这些其他类型也无效,我只是说这五种类型通过了这个特定的障碍。)
以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);
为什么会这样?向量具有数组具有的所有操作,对吗?注意:这是我无法真正处理的错误消息(针对第二个片段):
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 对 post 长度的限制而外包)
不,std::vector
不 有所有这些操作,不会隐式转换为数组。忽略 std::array
不会改变的事实,为了您的目的,它会更适合。
"A vector has all operations an array has" 不。数组隐式衰减为指针,向量不会。因此,当 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
可能有其他要求导致这些其他类型也无效,我只是说这五种类型通过了这个特定的障碍。)