Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:05

0001 // Copyright 2002 The Trustees of Indiana University.
0002 
0003 // Use, modification and distribution is subject to the Boost Software 
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //  Boost.MultiArray Library
0008 //  Authors: Ronald Garcia
0009 //           Jeremy Siek
0010 //           Andrew Lumsdaine
0011 //  See http://www.boost.org/libs/multi_array for documentation.
0012 
0013 #ifndef BOOST_MULTI_ARRAY_COPY_ARRAY_HPP
0014 #define BOOST_MULTI_ARRAY_COPY_ARRAY_HPP
0015 
0016 //
0017 // copy_array.hpp - generic code for copying the contents of one
0018 // Basic_MultiArray to another.  We assume that they are of the same
0019 // shape
0020 //
0021 #include "boost/type.hpp"
0022 #include "boost/assert.hpp"
0023 
0024 namespace boost {
0025 namespace detail {
0026 namespace multi_array {
0027 
0028 template <typename Element>
0029 class copy_dispatch {
0030 public:
0031   template <typename SourceIterator, typename DestIterator>
0032   static void copy_array (SourceIterator first, SourceIterator last,
0033                    DestIterator result) {
0034     while (first != last) {
0035       copy_array(*first++,*result++);
0036     }
0037   }
0038 private:
0039   // Array2 has to be passed by VALUE here because subarray
0040   // pseudo-references are temporaries created by iterator::operator*()
0041   template <typename Array1, typename Array2>
0042   static void copy_array (const Array1& source, Array2 dest) {
0043     copy_array(source.begin(),source.end(),dest.begin());
0044   }
0045 
0046   static void copy_array (const Element& source, Element& dest) {
0047     dest = source;
0048   }
0049 
0050 };
0051 
0052 
0053 template <typename Array1, typename Array2>
0054 void copy_array (Array1& source, Array2& dest) {
0055   BOOST_ASSERT(std::equal(source.shape(),source.shape()+source.num_dimensions(),
0056                           dest.shape()));
0057   // Dispatch to the proper function
0058   typedef typename Array1::element element_type;
0059   copy_dispatch<element_type>::
0060     copy_array(source.begin(),source.end(),dest.begin());
0061 }
0062 
0063 
0064 } // namespace multi_array
0065 } // namespace detail
0066 } // namespace boost
0067 
0068 #endif