stl_interaction.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. //
  11. // stl_interaction.cpp - Make sure multi_arrays work with STL containers.
  12. //
  13. #include <boost/core/lightweight_test.hpp>
  14. #include <boost/multi_array.hpp>
  15. #include <algorithm>
  16. #include <vector>
  17. int
  18. main()
  19. {
  20. using boost::extents;
  21. using boost::indices;
  22. typedef boost::multi_array_types::index_range range;
  23. typedef boost::multi_array<int,3> array3;
  24. typedef boost::multi_array<int,2> array2;
  25. typedef std::vector<array3> array3vec;
  26. int data[] = {
  27. 0,1,2,3,
  28. 4,5,6,7,
  29. 8,9,10,11,
  30. 12,13,14,15,
  31. 16,17,18,19,
  32. 20,21,22,23
  33. };
  34. const int data_size = 24;
  35. int insert[] = {
  36. 99,98,
  37. 97,96,
  38. };
  39. const int insert_size = 4;
  40. array3 myarray(extents[2][3][4]);
  41. myarray.assign(data,data+data_size);
  42. array3vec myvec(5,myarray);
  43. BOOST_TEST(myarray == myvec[1]);
  44. array3::array_view<2>::type myview =
  45. myarray[indices[1][range(0,2)][range(1,3)]];
  46. array2 filler(extents[2][2]);
  47. filler.assign(insert,insert+insert_size);
  48. // Modify a portion of myarray through a view (myview)
  49. myview = filler;
  50. myvec.push_back(myarray);
  51. BOOST_TEST(myarray != myvec[1]);
  52. BOOST_TEST(myarray == myvec[5]);
  53. return boost::report_errors();
  54. }