assign_to_array.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_to_array.cpp - multi_array should be constructible from any other
  12. // array type in the library.
  13. //
  14. //
  15. #include "generative_tests.hpp"
  16. #include <boost/array.hpp>
  17. #include <boost/multi_array.hpp>
  18. #include <boost/cstdlib.hpp>
  19. #include <algorithm>
  20. #include <iostream>
  21. bool equal(const int& a, const int& b)
  22. {
  23. return a == b;
  24. }
  25. template <typename ArrayA, typename ArrayB>
  26. bool equal(const ArrayA& A, const ArrayB& B)
  27. {
  28. typename ArrayA::const_iterator ia;
  29. typename ArrayB::const_iterator ib = B.begin();
  30. for (ia = A.begin(); ia != A.end(); ++ia, ++ib)
  31. if (!::equal(*ia, *ib))
  32. return false;
  33. return true;
  34. }
  35. template <typename Array>
  36. void access(Array& A, const mutable_array_tag&) {
  37. assign(A);
  38. access(A,const_array_tag());
  39. }
  40. template <typename Array>
  41. void access(Array& A, const const_array_tag&) {
  42. typedef boost::multi_array<int,3> array3;
  43. array3 acopy(A);
  44. BOOST_TEST(::equal(acopy,A));
  45. ++tests_run;
  46. }
  47. int main() {
  48. return run_generative_tests();
  49. }