williamr@2
|
1 |
// Copyright 2002 The Trustees of Indiana University.
|
williamr@2
|
2 |
|
williamr@2
|
3 |
// Use, modification and distribution is subject to the Boost Software
|
williamr@2
|
4 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
williamr@2
|
5 |
// http://www.boost.org/LICENSE_1_0.txt)
|
williamr@2
|
6 |
|
williamr@2
|
7 |
// Boost.MultiArray Library
|
williamr@2
|
8 |
// Authors: Ronald Garcia
|
williamr@2
|
9 |
// Jeremy Siek
|
williamr@2
|
10 |
// Andrew Lumsdaine
|
williamr@2
|
11 |
// See http://www.boost.org/libs/multi_array for documentation.
|
williamr@2
|
12 |
|
williamr@2
|
13 |
#ifndef COPY_ARRAY_RG092101_HPP
|
williamr@2
|
14 |
#define COPY_ARRAY_RG092101_HPP
|
williamr@2
|
15 |
|
williamr@2
|
16 |
//
|
williamr@2
|
17 |
// copy_array.hpp - generic code for copying the contents of one
|
williamr@2
|
18 |
// Basic_MultiArray to another. We assume that they are of the same
|
williamr@2
|
19 |
// shape
|
williamr@2
|
20 |
//
|
williamr@2
|
21 |
#include "boost/type.hpp"
|
williamr@2
|
22 |
#include <cassert>
|
williamr@2
|
23 |
|
williamr@2
|
24 |
namespace boost {
|
williamr@2
|
25 |
namespace detail {
|
williamr@2
|
26 |
namespace multi_array {
|
williamr@2
|
27 |
|
williamr@2
|
28 |
template <typename Element>
|
williamr@2
|
29 |
class copy_dispatch {
|
williamr@2
|
30 |
public:
|
williamr@2
|
31 |
template <typename SourceIterator, typename DestIterator>
|
williamr@2
|
32 |
static void copy_array (SourceIterator first, SourceIterator last,
|
williamr@2
|
33 |
DestIterator result) {
|
williamr@2
|
34 |
while (first != last) {
|
williamr@2
|
35 |
copy_array(*first++,*result++);
|
williamr@2
|
36 |
}
|
williamr@2
|
37 |
}
|
williamr@2
|
38 |
private:
|
williamr@2
|
39 |
// Array2 has to be passed by VALUE here because subarray
|
williamr@2
|
40 |
// pseudo-references are temporaries created by iterator::operator*()
|
williamr@2
|
41 |
template <typename Array1, typename Array2>
|
williamr@2
|
42 |
static void copy_array (const Array1& source, Array2 dest) {
|
williamr@2
|
43 |
copy_array(source.begin(),source.end(),dest.begin());
|
williamr@2
|
44 |
}
|
williamr@2
|
45 |
|
williamr@2
|
46 |
static void copy_array (const Element& source, Element& dest) {
|
williamr@2
|
47 |
dest = source;
|
williamr@2
|
48 |
}
|
williamr@2
|
49 |
|
williamr@2
|
50 |
};
|
williamr@2
|
51 |
|
williamr@2
|
52 |
|
williamr@2
|
53 |
template <typename Array1, typename Array2>
|
williamr@2
|
54 |
void copy_array (Array1& source, Array2& dest) {
|
williamr@2
|
55 |
assert(std::equal(source.shape(),source.shape()+source.num_dimensions(),
|
williamr@2
|
56 |
dest.shape()));
|
williamr@2
|
57 |
// Dispatch to the proper function
|
williamr@2
|
58 |
typedef typename Array1::element element_type;
|
williamr@2
|
59 |
copy_dispatch<element_type>::
|
williamr@2
|
60 |
copy_array(source.begin(),source.end(),dest.begin());
|
williamr@2
|
61 |
}
|
williamr@2
|
62 |
|
williamr@2
|
63 |
|
williamr@2
|
64 |
} // namespace multi_array
|
williamr@2
|
65 |
} // namespace detail
|
williamr@2
|
66 |
} // namespace boost
|
williamr@2
|
67 |
|
williamr@2
|
68 |
#endif // COPY_ARRAY_RG092101_HPP
|