]> git.lyx.org Git - lyx.git/blob - boost/boost/multi_array/copy_array.hpp
2002-05-24 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[lyx.git] / boost / boost / multi_array / copy_array.hpp
1 #ifndef COPY_ARRAY_RG092101_HPP
2 #define COPY_ARRAY_RG092101_HPP
3
4 //
5 // copy_array.hpp - generic code for copying the contents of one
6 // Basic_MultiArray to another.  We assume that they are of the same
7 // shape
8 //
9 #include "boost/type.hpp"
10 #include <cassert>
11
12 namespace boost {
13 namespace detail {
14 namespace multi_array {
15
16 template <typename Element>
17 class copy_dispatch {
18 public:
19   template <typename SourceIterator, typename DestIterator>
20   static void copy_array (SourceIterator first, SourceIterator last,
21                    DestIterator result) {
22     while (first != last) {
23       copy_array(*first++,*result++);
24     }
25   }
26 private:
27   // Array2 has to be passed by VALUE here because subarray
28   // pseudo-references are temporaries created by iterator::operator*()
29   template <typename Array1, typename Array2>
30   static void copy_array (const Array1& source, Array2 dest) {
31     copy_array(source.begin(),source.end(),dest.begin());
32   }
33
34   static void copy_array (const Element& source, Element& dest) {
35     dest = source;
36   }
37
38 };
39
40
41 template <typename Array1, typename Array2>
42 void copy_array (Array1& source, Array2& dest) {
43   assert(std::equal(source.shape(),source.shape()+source.num_dimensions(),
44                     dest.shape()));
45   // Dispatch to the proper function
46   typedef typename Array1::element element_type;
47   copy_dispatch<element_type>::
48     copy_array(source.begin(),source.end(),dest.begin());
49 }
50
51
52 } // namespace multi_array
53 } // namespace detail
54 } // namespace boost
55
56 #endif // COPY_ARRAY_RG092101_HPP