Chris@16: // Copyright 2002 The Trustees of Indiana University. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // Boost.MultiArray Library Chris@16: // Authors: Ronald Garcia Chris@16: // Jeremy Siek Chris@16: // Andrew Lumsdaine Chris@16: // See http://www.boost.org/libs/multi_array for documentation. Chris@16: Chris@16: #ifndef COPY_ARRAY_RG092101_HPP Chris@16: #define COPY_ARRAY_RG092101_HPP Chris@16: Chris@16: // Chris@16: // copy_array.hpp - generic code for copying the contents of one Chris@16: // Basic_MultiArray to another. We assume that they are of the same Chris@16: // shape Chris@16: // Chris@16: #include "boost/type.hpp" Chris@16: #include "boost/assert.hpp" Chris@16: Chris@16: namespace boost { Chris@16: namespace detail { Chris@16: namespace multi_array { Chris@16: Chris@16: template Chris@16: class copy_dispatch { Chris@16: public: Chris@16: template Chris@16: static void copy_array (SourceIterator first, SourceIterator last, Chris@16: DestIterator result) { Chris@16: while (first != last) { Chris@16: copy_array(*first++,*result++); Chris@16: } Chris@16: } Chris@16: private: Chris@16: // Array2 has to be passed by VALUE here because subarray Chris@16: // pseudo-references are temporaries created by iterator::operator*() Chris@16: template Chris@16: static void copy_array (const Array1& source, Array2 dest) { Chris@16: copy_array(source.begin(),source.end(),dest.begin()); Chris@16: } Chris@16: Chris@16: static void copy_array (const Element& source, Element& dest) { Chris@16: dest = source; Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: Chris@16: template Chris@16: void copy_array (Array1& source, Array2& dest) { Chris@16: BOOST_ASSERT(std::equal(source.shape(),source.shape()+source.num_dimensions(), Chris@16: dest.shape())); Chris@16: // Dispatch to the proper function Chris@16: typedef typename Array1::element element_type; Chris@16: copy_dispatch:: Chris@16: copy_array(source.begin(),source.end(),dest.begin()); Chris@16: } Chris@16: Chris@16: Chris@16: } // namespace multi_array Chris@16: } // namespace detail Chris@16: } // namespace boost Chris@16: Chris@16: #endif // COPY_ARRAY_RG092101_HPP