inner_productd的用法

来源:互联网 发布:java中的泛型集合 编辑:程序博客网 时间:2024/05/24 05:03
#include <iostream>#include <numeric>using namespace std;string combine(const string &x, const string &y){    return "("+x+","+y+")";}string concatenate(const string &x,const string &y){    if(x.empty())    {        return y;    }    return x+", "+y;}int main(void){    int arr1[] = {1, 3, 9, 4} ;    int arr2[] = {1, 1, 1, 2} ;    int totalValue = inner_product(arr1, arr1 + sizeof (arr1) / sizeof (*arr1), arr2, 0);    cout << totalValue << endl ;    totalValue = inner_product(arr1, arr1 + sizeof (arr1) / sizeof (*arr1), arr2, 0, plus<int> (), multiplies<int> ()) ;    cout << totalValue << endl ;    string s1[] = {"if","string","sort"};    string s2[] = {"keyword","library type","algorithm"};    cout << inner_product(s1, s1 + sizeof(s1) / sizeof(*s1), s2, string(), concatenate, combine) << endl;    return 0;}

 
原创粉丝点击