foreach_test2.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2002 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Boost.MultiArray Library
  6. // Authors: Ronald Garcia
  7. // Jeremy Siek
  8. // Andrew Lumsdaine
  9. // See http://www.boost.org/libs/multi_array for documentation.
  10. #include "boost/multi_array.hpp"
  11. #include "for_each.hpp"
  12. #include <algorithm>
  13. struct times_five {
  14. double operator()(const int& val) { return val*5.0; }
  15. };
  16. int main() {
  17. typedef boost::multi_array<double,1> array;
  18. double data[] = {
  19. 1.0, 2.0, 3.0,
  20. 4.0, 5.0, 6.0,
  21. 7.0, 8.0, 9.0
  22. };
  23. const int data_size=9;
  24. array A(boost::extents[9]);
  25. A.assign(data,data+data_size);
  26. #if 0
  27. std::copy(A.begin(),A.end(),
  28. std::ostream_iterator<double>(std::cout,","));
  29. std::cout << "\n";
  30. #endif
  31. for_each(A,times_five());
  32. #if 0
  33. std::copy(A.begin(),A.end(),
  34. std::ostream_iterator<double>(std::cout,","));
  35. std::cout << "\n";
  36. #endif
  37. return 0;
  38. }