assign.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // assign.cpp - Test out operator=() on the different types
  12. //
  13. //
  14. #include "generative_tests.hpp"
  15. #include <boost/array.hpp>
  16. #include <boost/multi_array.hpp>
  17. #include <boost/cstdlib.hpp>
  18. #include <algorithm>
  19. #include <iostream>
  20. bool equal(const int& a, const int& b)
  21. {
  22. return a == b;
  23. }
  24. template <typename ArrayA, typename ArrayB>
  25. bool equal(const ArrayA& A, const ArrayB& B)
  26. {
  27. typename ArrayA::const_iterator ia;
  28. typename ArrayB::const_iterator ib = B.begin();
  29. for (ia = A.begin(); ia != A.end(); ++ia, ++ib)
  30. if (!::equal(*ia, *ib))
  31. return false;
  32. return true;
  33. }
  34. template <typename Array>
  35. void access(Array& A, const mutable_array_tag&) {
  36. assign(A);
  37. typedef boost::multi_array<int,3> array3;
  38. int insert[] = {
  39. 99,98,97,96,
  40. 95,94,93,92,
  41. 91,90,89,88,
  42. 87,86,85,84,
  43. 83,82,81,80,
  44. 79,78,77,76
  45. };
  46. const int insert_size = 2*3*4;
  47. array3 filler(boost::extents[2][3][4]);
  48. filler.assign(insert,insert+insert_size);
  49. A = filler;
  50. BOOST_TEST(::equal(A,filler));
  51. ++tests_run;
  52. }
  53. template <typename Array>
  54. void access(Array&, const const_array_tag&) {
  55. }
  56. int main() {
  57. return run_generative_tests();
  58. }