move.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*=============================================================================
  2. Copyright (c) 2001-2013 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_MOVE_01192013_2225)
  7. #define FUSION_MOVE_01192013_2225
  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. #include <utility> // for std::move
  19. #if defined (BOOST_MSVC)
  20. # pragma warning(push)
  21. # pragma warning (disable: 4100) // unreferenced formal parameter
  22. #endif
  23. namespace boost { namespace fusion
  24. {
  25. namespace detail
  26. {
  27. template <typename Seq1, typename Seq2>
  28. struct sequence_move
  29. {
  30. typedef typename result_of::end<Seq1>::type end1_type;
  31. typedef typename result_of::end<Seq2>::type end2_type;
  32. template <typename I1, typename I2>
  33. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  34. static void
  35. call(I1 const&, I2 const&, mpl::true_)
  36. {
  37. }
  38. template <typename I1, typename I2>
  39. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  40. static void
  41. call(I1 const& src, I2 const& dest, mpl::false_)
  42. {
  43. *dest = std::move(*src);
  44. call(fusion::next(src), fusion::next(dest));
  45. }
  46. template <typename I1, typename I2>
  47. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  48. static void
  49. call(I1 const& src, I2 const& dest)
  50. {
  51. typename result_of::equal_to<I1, end1_type>::type eq;
  52. return call(src, dest, eq);
  53. }
  54. };
  55. }
  56. namespace result_of
  57. {
  58. template <typename Seq1, typename Seq2>
  59. struct move
  60. : enable_if<mpl::and_<
  61. traits::is_sequence<Seq1>,
  62. traits::is_sequence<Seq2>
  63. > > {};
  64. }
  65. template <typename Seq1, typename Seq2>
  66. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  67. inline typename result_of::move<Seq1, Seq2>::type
  68. move(Seq1&& src, Seq2& dest)
  69. {
  70. BOOST_STATIC_ASSERT(
  71. result_of::size<Seq1>::value <= result_of::size<Seq2>::value);
  72. detail::sequence_move<
  73. Seq1, Seq2>::
  74. call(fusion::begin(src), fusion::begin(dest));
  75. }
  76. }}
  77. #if defined (BOOST_MSVC)
  78. # pragma warning(pop)
  79. #endif
  80. #endif