为什么提升需要 &向量[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对帖子长度的限制而外包)
"向量具有数组具有的所有操作" 否。 数组隐式衰减到指针,矢量不会。 因此,当 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
可能有其他要求导致这些其他类型的类型也无效,我只是说这五种类型通过了这个特定的障碍。
不,std::vector
没有所有这些操作,也不会隐式转换为数组。忽略std::array
不会改变这一事实,为了您的目的,它会更适合。
相关文章:
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 为什么我不能将一个对象push_back到属于另一个类的对象向量中?
- 为什么一个向量上的多线程操作很慢
- 为什么C++常量模板化向量在使用之前没有初始化?
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- C ++中的StringStream有助于使用向量从字符串中提取逗号分隔的整数,而不是空格分隔的整数,为什么?
- 为什么向量内部的指针在从函数返回时会发生变化?
- 为什么不允许使用可变长度数组作为向量元素?
- 为什么我在向量初始化时收到此错误?
- 为什么我必须在作案操作中解析向量的大小?
- 为什么通过 vector<reference_wrapper> 的元素删除引用的值<T>不会使向量无效?
- 当键值是 std 向量时,为什么使用 at in C++ 访问映射值如此缓慢?
- 为什么即使使用 for 循环遍历我的向量,它也没有输出到控制台?(C++)
- 为什么负数不取模向量大小给出负数?
- 为什么这种向量声明无效?
- 为什么在向量上使用 std::find() 时会出现错误?
- 为什么在此排序算法实现中,向量明显比数组慢?
- 为什么我的向量::擦除调用会抛出"vector subscript out of range"?
- 在 C++ 中将元素添加到空向量:为什么 push.back 有效而 [] 无效
- 用不重复的随机数填充向量.为什么不工作