Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_UTILITY_COPY_H
00002 #define OPENTISSUE_UTILITY_UTILITY_COPY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/type_traits.hpp>
00013
00014 #include <cstring>
00015
00016 namespace OpenTissue { namespace utility
00017 {
00018
00019
00020 namespace detail
00021 {
00022 template <bool b>
00023 struct copier
00024 {
00025 template <typename I1, typename I2>
00026 static I2 do_copy( I1 first, I1 last, I2 out )
00027 {
00028 std::cout << "-- OpenTissue::utility::copy (normal)" << std::endl;
00029 while ( first != last )
00030 {
00031 *out = *first;
00032 ++out;
00033 ++first;
00034 }
00035 return out;
00036 }
00037 };
00038
00039 template <>
00040 struct copier<true>
00041 {
00042 template <typename I1, typename I2>
00043 static I2 do_copy( I1 first, I1 last, I2 out )
00044 {
00045
00046 memcpy( &( *out ), &( *first ), ( last - first ) * sizeof( typename I2::value_type ) );
00047 return out + ( last - first );
00048 }
00049 };
00050 }
00051
00052 template <typename I1, typename I2>
00053 I2 copy( I1 first, I1 last, I2 out )
00054 {
00055 typedef typename boost::remove_cv<typename std::iterator_traits<I1>::value_type>::type v1_t;
00056 typedef typename boost::remove_cv<typename std::iterator_traits<I2>::value_type>::type v2_t;
00057
00058 return detail::copier <
00059 ::boost::type_traits::ice_and <
00060 ::boost::is_same<v1_t, v2_t>::value,
00061
00062
00063 ::boost::has_trivial_assign<v1_t>::value
00064 > ::value > ::do_copy( first, last, out );
00065 }
00066 }}
00067
00068
00069 #endif