copy.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_COPY_02162011_2308)
  7. #define FUSION_COPY_02162011_2308
  8. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  9. #include <boost/fusion/sequence/intrinsic/end.hpp>
  10. #include <boost/fusion/sequence/intrinsic/size.hpp>
  11. #include <boost/fusion/sequence/comparison/detail/equal_to.hpp>
  12. #include <boost/fusion/support/is_sequence.hpp>
  13. #include <boost/config.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/utility/enable_if.hpp>
  16. #include <boost/type_traits/ice.hpp>
  17. #if defined (BOOST_MSVC)
  18. # pragma warning(push)
  19. # pragma warning (disable: 4100) // unreferenced formal parameter
  20. #endif
  21. namespace boost { namespace fusion
  22. {
  23. namespace detail
  24. {
  25. template <typename Seq1, typename Seq2>
  26. struct sequence_copy
  27. {
  28. typedef typename result_of::end<Seq1>::type end1_type;
  29. typedef typename result_of::end<Seq2>::type end2_type;
  30. template <typename I1, typename I2>
  31. static void
  32. call(I1 const&, I2 const&, mpl::true_)
  33. {
  34. }
  35. template <typename I1, typename I2>
  36. static void
  37. call(I1 const& src, I2 const& dest, mpl::false_)
  38. {
  39. *dest = *src;
  40. call(fusion::next(src), fusion::next(dest));
  41. }
  42. template <typename I1, typename I2>
  43. static void
  44. call(I1 const& src, I2 const& dest)
  45. {
  46. typename result_of::equal_to<I1, end1_type>::type eq;
  47. return call(src, dest, eq);
  48. }
  49. };
  50. }
  51. template <typename Seq1, typename Seq2>
  52. inline
  53. typename
  54. enable_if_c<
  55. type_traits::ice_and<
  56. traits::is_sequence<Seq1>::value
  57. , traits::is_sequence<Seq2>::value
  58. >::value,
  59. void
  60. >::type
  61. copy(Seq1 const& src, Seq2& dest)
  62. {
  63. BOOST_STATIC_ASSERT(
  64. result_of::size<Seq1>::value <= result_of::size<Seq2>::value);
  65. detail::sequence_copy<
  66. Seq1 const, Seq2>::
  67. call(fusion::begin(src), fusion::begin(dest));
  68. }
  69. }}
  70. #if defined (BOOST_MSVC)
  71. # pragma warning(pop)
  72. #endif
  73. #endif