foreach_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // foreach_test.cpp
  11. // Let's see if this stuff works
  12. #include "boost/multi_array.hpp"
  13. #include "for_each.hpp"
  14. #include <algorithm>
  15. struct times_five {
  16. double operator()(const int& val) { return val*5.0; }
  17. };
  18. int main() {
  19. typedef boost::multi_array<double,2> array;
  20. double data[] = {
  21. 1.0, 2.0, 3.0,
  22. 4.0, 5.0, 6.0,
  23. 7.0, 8.0, 9.0
  24. };
  25. const int data_size=9;
  26. array A(boost::extents[3][3]);
  27. A.assign(data,data+data_size);
  28. #if 0
  29. std::copy(A.data(),A.data()+A.num_elements(),
  30. std::ostream_iterator<double>(std::cout,","));
  31. std::cout << "\n";
  32. #endif
  33. for_each(A,times_five());
  34. #if 0
  35. std::copy(A.data(),A.data()+A.num_elements(),
  36. std::ostream_iterator<double>(std::cout,","));
  37. std::cout << "\n";
  38. #endif
  39. return 0;
  40. }