fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <ostream>
  5. #include <numeric>
  6. #include <cstdlib>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. template<typename InputIterator1,typename InputIterator2,typename ValueType>
  12. ValueType dot_product( InputIterator1 first, InputIterator1 last, InputIterator2 another, ValueType init)
  13. {
  14. while(first!=last)
  15. {
  16. init += (*first) * (*another) ;
  17. ++first;
  18. ++another;
  19. }
  20. return init;
  21. }
  22.  
  23. int main()
  24. {
  25. vector<int> v1,v2;
  26. generate_n( back_inserter(v1), 256, rand );
  27. generate_n( back_inserter(v2), v1.size(), rand );
  28. cout << dot_product( v1.begin(), v1.end(), v2.begin(), 0 ) << endl;
  29. }
  30.  
Success #stdin #stdout 0.01s 2812KB
stdin
Standard input is empty
stdout
-1760782322