c++ - inner_product of map -
Internal product can not be applied on a map. I have the following code:
std :: map & lt; Class A, Class B & gt; S; Std :: map & lt; Class A, Class B & gt; :: const_iterator vit = s.begin (); Long double x = std :: inner_product (vit-> first, vit- & gt; second, vit-> first, 0.0); But I get a no-match function for internal_product error.
This can be applied to the map, which is the creatively selected font Given, but Inner_product is expected for iterators, while vit-> First, is a const A and vit-> second a b . For example,
std :: map & lt; Int, double & gt; M = {{1, 0.1}, {2, 0.2}}; Typedef std :: map & lt; Int, double> :: value_type val_t; Double x = std :: inner_product (m.begin (), m.end (), m.begin (), 0.0, std :: plus (), [] (val_t lhs, val_t rhs ) {Return lhs .first * rhs.second;});
Comments
Post a Comment