Skip to content
Permalink
Browse files

original formating of utility_copy.h plus adding boost header for no …

…compilation error
  • Loading branch information
Markus Walzthöni
Markus Walzthöni committed Dec 10, 2019
1 parent c7d2e47 commit d82c28ea4be9238cf7c43ef4afb51ad3c8fc0d68
Showing with 45 additions and 47 deletions.
  1. +45 −47 OpenTissue/utility/utility_copy.h
@@ -14,59 +14,57 @@

#include <cstring> // for memcpy()

namespace OpenTissue
namespace OpenTissue { namespace utility
{
namespace utility
{
// Special implementation of copy, that uses memcpy for compatible types
// (based on example from boost::type_traits)
namespace detail
{
template <bool b>
struct copier
{
template <typename I1, typename I2>
static I2 do_copy(I1 first, I1 last, I2 out)
// Special implementation of copy, that uses memcpy for compatible types
// (based on example from boost::type_traits)
namespace detail
{
std::cout << "-- OpenTissue::utility::copy (normal)" << std::endl;
while (first != last)
template <bool b>
struct copier
{
*out = *first;
++out;
++first;
}
return out;
}
};
template <typename I1, typename I2>
static I2 do_copy( I1 first, I1 last, I2 out )
{
std::cout << "-- OpenTissue::utility::copy (normal)" << std::endl;
while ( first != last )
{
*out = *first;
++out;
++first;
}
return out;
}
};

template <>
struct copier<true>
{
template <typename I1, typename I2>
static I2 do_copy( I1 first, I1 last, I2 out )
{
//std::cout << "-- OpenTissue::utility::copy (fast)" << std::endl;
memcpy( &( *out ), &( *first ), ( last - first ) * sizeof( typename I2::value_type ) );
return out + ( last - first );
}
};
} // namespace detail

template <>
struct copier<true>
{
template <typename I1, typename I2>
static I2 do_copy(I1 first, I1 last, I2 out)
I2 copy( I1 first, I1 last, I2 out )
{
//std::cout << "-- OpenTissue::utility::copy (fast)" << std::endl;
memcpy(&(*out), &(*first), (last - first) * sizeof(typename I2::value_type));
return out + (last - first);
}
};
} // namespace detail
typedef typename boost::remove_cv<typename std::iterator_traits<I1>::value_type>::type v1_t;
typedef typename boost::remove_cv<typename std::iterator_traits<I2>::value_type>::type v2_t;

template <typename I1, typename I2>
I2 copy(I1 first, I1 last, I2 out)
{
typedef typename boost::remove_cv<typename std::iterator_traits<I1>::value_type>::type v1_t;
typedef typename boost::remove_cv<typename std::iterator_traits<I2>::value_type>::type v2_t;

return detail::copier<
::boost::type_traits::ice_and<
::boost::is_same<v1_t, v2_t>::value,
// ::boost::is_pointer<I1>::value,
// ::boost::is_pointer<I2>::value,
::boost::has_trivial_assign<v1_t>::value>::value>::do_copy(first, last, out);
}
} // namespace utility
} // namespace OpenTissue
return detail::copier <
::boost::type_traits::ice_and <
::boost::is_same<v1_t, v2_t>::value,
// ::boost::is_pointer<I1>::value,
// ::boost::is_pointer<I2>::value,
::boost::has_trivial_assign<v1_t>::value
> ::value > ::do_copy( first, last, out );
}
}} // namespace OpenTissue::utility

// OPENTISSUE_UTILITY_UTILITY_COPY_H
#endif
#endif

0 comments on commit d82c28e

Please sign in to comment.
You can’t perform that action at this time.