1 // Copyright (C) 2002 Ronald Garcia
3 // Permission to copy, use, sell and distribute this software is granted
4 // provided this copyright notice appears in all copies.
5 // Permission to modify the code and to distribute modified code is granted
6 // provided this copyright notice appears in all copies, and a notice
7 // that the code was modified is included with the copyright notice.
9 // This software is provided "as is" without express or implied warranty,
10 // and with no claim as to its suitability for any purpose.
13 #ifndef COPY_ARRAY_RG092101_HPP
14 #define COPY_ARRAY_RG092101_HPP
17 // copy_array.hpp - generic code for copying the contents of one
18 // Basic_MultiArray to another. We assume that they are of the same
21 #include "boost/type.hpp"
26 namespace multi_array {
28 template <typename Element>
31 template <typename SourceIterator, typename DestIterator>
32 static void copy_array (SourceIterator first, SourceIterator last,
33 DestIterator result) {
34 while (first != last) {
35 copy_array(*first++,*result++);
39 // Array2 has to be passed by VALUE here because subarray
40 // pseudo-references are temporaries created by iterator::operator*()
41 template <typename Array1, typename Array2>
42 static void copy_array (const Array1& source, Array2 dest) {
43 copy_array(source.begin(),source.end(),dest.begin());
46 static void copy_array (const Element& source, Element& dest) {
53 template <typename Array1, typename Array2>
54 void copy_array (Array1& source, Array2& dest) {
55 assert(std::equal(source.shape(),source.shape()+source.num_dimensions(),
57 // Dispatch to the proper function
58 typedef typename Array1::element element_type;
59 copy_dispatch<element_type>::
60 copy_array(source.begin(),source.end(),dest.begin());
64 } // namespace multi_array
68 #endif // COPY_ARRAY_RG092101_HPP