inner_product of map
inner_product of map
inner_product可以不应用于映射吗?我有以下代码:
std::map<class A, class B> s;
std::map<class A, class B>::const_iterator vit=s.begin();
long double x = std::inner_product(vit->first,vit->second,vit->first,0.0);
但我得到一个不匹配的函数inner_product错误
它当然可以应用于映射,给定创造性地选择的函子,但inner_product
期望迭代器,而vit->first
是const A
, vit->second
是B
。
std::map<int, double> m = {{1, 0.1}, {2, 0.2}};
typedef std::map<int, double>::value_type val_t;
double x = std::inner_product(m.begin(), m.end(), m.begin(), 0.0,
std::plus<double>(),
[](val_t lhs, val_t rhs){return lhs.first * rhs.second;});
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- Usages of std::move
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 初始化 std::数组 of Eigen::Map
- 如何在 std::map 中从 std::vector of std::p air 中获取输入?
- 使用 operator[] 访问私有 std::map of unique_ptr
- C++ Equivalent of Java Map<String, Object>
- std::map with iterators to std::list from iterators of std::
- C++ initialize map of pairs
- The ordering of an std::map
- inner_product of map
- Make_pair of std::map -如何仅在键未列出时生成一对(否则更新键)