/*******************************************************************************
*
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
*
* Copyright (C) 2011 by O. Parcollet
*
* TRIQS is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* TRIQS. If not, see .
*
******************************************************************************/
#ifndef TRIQS_MEMCOPY_H
#define TRIQS_MEMCOPY_H
#include "../../utility/exceptions.hpp"
namespace triqs { namespace arrays { namespace storages {
// beware : complex is not a pod
template struct is_scalar_or_pod : std::integral_constant::value || triqs::is_complex::value || std::is_pod::value > {};
// copy such that it is a fast memcpy for scalar / pod objects
// when not a scalar object, loop on elements
template
void memcopy_impl (T1 * restrict p1, const T2 * restrict p2, size_t size, std::false_type) { for (size_t i = 0; i < size; ++i) p1[i] = p2[i]; }
template
void memcopy_impl (T * restrict p1, const T * restrict p2, size_t size, std::true_type) {
if (std::abs(p2-p1)>size) {memcpy (p1, p2, size * sizeof(T));} // guard against aliasing of data
else { memcopy_impl(p1,p2,size,std::false_type());}
}
template
void memcopy (T1 * restrict p1, const T2 * restrict p2, size_t size) {
constexpr bool use_memcpy = std::is_pod::value &&
std::is_same< typename std::remove_cv::type, typename std::remove_cv::type>::value;
memcopy_impl(p1,p2,size,std::integral_constant());
}
}}}
#endif