copy.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/support/config.hpp>
  9. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  10. #include <boost/fusion/sequence/intrinsic/end.hpp>
  11. #include <boost/fusion/sequence/intrinsic/size.hpp>
  12. #include <boost/fusion/sequence/comparison/detail/equal_to.hpp>
  13. #include <boost/fusion/support/is_sequence.hpp>
  14. #include <boost/config.hpp>
  15. #include <boost/static_assert.hpp>
  16. #include <boost/utility/enable_if.hpp>
  17. #include <boost/mpl/and.hpp>
  18. #if defined (BOOST_MSVC)
  19. # pragma warning(push)
  20. # pragma warning (disable: 4100) // unreferenced formal parameter
  21. #endif
  22. namespace boost { namespace fusion
  23. {
  24. namespace detail
  25. {
  26. template <typename Seq1, typename Seq2>
  27. struct sequence_copy
  28. {
  29. typedef typename result_of::end<Seq1>::type end1_type;
  30. typedef typename result_of::end<Seq2>::type end2_type;
  31. template <typename I1, typename I2>
  32. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  33. static void
  34. call(I1 const&, I2 const&, mpl::true_)
  35. {
  36. }
  37. template <typename I1, typename I2>
  38. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  39. static void
  40. call(I1 const& src, I2 const& dest, mpl::false_)
  41. {
  42. *dest = *src;
  43. call(fusion::next(src), fusion::next(dest));
  44. }
  45. template <typename I1, typename I2>
  46. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  47. static void
  48. call(I1 const& src, I2 const& dest)
  49. {
  50. typename result_of::equal_to<I1, end1_type>::type eq;
  51. return call(src, dest, eq);
  52. }
  53. };
  54. }
  55. namespace result_of
  56. {
  57. template <typename Seq1, typename Seq2>
  58. struct copy
  59. : enable_if<mpl::and_<
  60. traits::is_sequence<Seq1>,
  61. traits::is_sequence<Seq2>
  62. > > {};
  63. }
  64. template <typename Seq1, typename Seq2>
  65. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  66. inline typename result_of::copy<Seq1 const, Seq2>::type
  67. copy(Seq1 const& src, Seq2& dest)
  68. {
  69. BOOST_STATIC_ASSERT(
  70. result_of::size<Seq1>::value <= result_of::size<Seq2>::value);
  71. detail::sequence_copy<
  72. Seq1 const, Seq2>::
  73. call(fusion::begin(src), fusion::begin(dest));
  74. }
  75. }}
  76. #if defined (BOOST_MSVC)
  77. # pragma warning(pop)
  78. #endif
  79. #endif