home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl2vac.zip / STLport-4_5_3.zip / STLport-4.5.3 / test / regression / inrprod2.cpp < prev    next >
C/C++ Source or Header  |  2000-12-07  |  1KB  |  50 lines

  1. // STLport regression testsuite component.
  2. // To compile as a separate example, please #define MAIN.
  3.  
  4. #include <vector>
  5. #include <numeric>
  6. #include <iostream>
  7. #include <iterator>
  8. #include <string>
  9.  
  10. #ifdef MAIN 
  11. #define inrprod2_test main
  12. #endif
  13. static int add(int a_, int b_)
  14. {
  15.   return a_ + b_;
  16. }
  17.  
  18. static int mult(int a_, int b_)
  19. {
  20.   return a_ * b_;
  21. }
  22.  
  23. #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
  24. using namespace std;
  25. #endif
  26. int inrprod2_test(int, char**)
  27. {
  28.   cout<<"Results of inrprod2_test:"<<endl;
  29.  
  30.   vector <int> v1(3);
  31.   vector <int> v2(v1.size());
  32.   for(int i = 0; i < v1.size(); i++)
  33.   {
  34.     v1[i] = i + 1;
  35.     v2[i] = v1.size() - i;
  36.   }
  37.   ostream_iterator<int> iter(cout, " ");
  38.   cout << "Inner product(product of sums):\n\t";
  39.   copy(v1.begin(), v1.end(), iter);
  40.   cout << "\n\t";
  41.   copy(v2.begin(), v2.end(), iter);
  42.   int result =
  43.     inner_product(v1.begin(), v1.end(),
  44.                    v2.begin(),
  45.                    1,
  46.                    mult, add);
  47.   cout << "\nis: " << result << endl;
  48.   return 0;
  49. }
  50.