transform_view.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_TRANSFORM_VIEW_07162005_1037)
  7. #define FUSION_TRANSFORM_VIEW_07162005_1037
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/static_assert.hpp>
  10. #include <boost/fusion/support/detail/access.hpp>
  11. #include <boost/fusion/support/is_view.hpp>
  12. #include <boost/fusion/support/category_of.hpp>
  13. #include <boost/fusion/view/transform_view/transform_view_iterator.hpp>
  14. #include <boost/fusion/view/transform_view/transform_view_fwd.hpp>
  15. #include <boost/fusion/view/transform_view/detail/begin_impl.hpp>
  16. #include <boost/fusion/view/transform_view/detail/end_impl.hpp>
  17. #include <boost/fusion/view/transform_view/detail/at_impl.hpp>
  18. #include <boost/fusion/view/transform_view/detail/value_at_impl.hpp>
  19. #include <boost/fusion/view/detail/strictest_traversal.hpp>
  20. #include <boost/fusion/container/vector/vector10.hpp>
  21. #include <boost/fusion/sequence/intrinsic/size.hpp>
  22. #include <boost/fusion/support/sequence_base.hpp>
  23. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  24. #include <boost/fusion/sequence/intrinsic/end.hpp>
  25. #include <boost/fusion/sequence/intrinsic/size.hpp>
  26. #include <boost/mpl/bool.hpp>
  27. #ifdef _MSC_VER
  28. # pragma warning(push)
  29. # pragma warning(disable: 4512) // assignment operator could not be generated.
  30. #endif
  31. namespace boost { namespace fusion
  32. {
  33. struct void_;
  34. struct transform_view_tag;
  35. struct transform_view2_tag;
  36. struct fusion_sequence_tag;
  37. // Binary Version
  38. template <typename Sequence1, typename Sequence2, typename F>
  39. struct transform_view : sequence_base<transform_view<Sequence1, Sequence2, F> >
  40. {
  41. BOOST_STATIC_ASSERT(result_of::size<Sequence1>::value == result_of::size<Sequence2>::value);
  42. typedef transform_view2_tag fusion_tag;
  43. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  44. typedef mpl::true_ is_view;
  45. typedef typename traits::category_of<Sequence1>::type category1;
  46. typedef typename traits::category_of<Sequence2>::type category2;
  47. typedef typename detail::strictest_traversal<
  48. fusion::vector2<Sequence1, Sequence2> >::type category;
  49. typedef typename result_of::begin<Sequence1>::type first1_type;
  50. typedef typename result_of::begin<Sequence2>::type first2_type;
  51. typedef typename result_of::end<Sequence1>::type last1_type;
  52. typedef typename result_of::end<Sequence2>::type last2_type;
  53. typedef typename result_of::size<Sequence1>::type size;
  54. typedef Sequence1 sequence1_type;
  55. typedef Sequence2 sequence2_type;
  56. typedef F transform_type;
  57. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  58. transform_view(Sequence1& in_seq1, Sequence2& in_seq2, F const& binop)
  59. : f(binop)
  60. , seq1(in_seq1)
  61. , seq2(in_seq2)
  62. {}
  63. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  64. first1_type first1() const { return fusion::begin(seq1); }
  65. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  66. first2_type first2() const { return fusion::begin(seq2); }
  67. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  68. last1_type last1() const { return fusion::end(seq1); }
  69. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  70. last2_type last2() const { return fusion::end(seq2); }
  71. transform_type f;
  72. typename mpl::if_<traits::is_view<Sequence1>, Sequence1, Sequence1&>::type seq1;
  73. typename mpl::if_<traits::is_view<Sequence2>, Sequence2, Sequence2&>::type seq2;
  74. };
  75. // Unary Version
  76. template <typename Sequence, typename F>
  77. #if defined(BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS)
  78. struct transform_view<Sequence, F, void_> : sequence_base<transform_view<Sequence, F, void_> >
  79. #else
  80. struct transform_view<Sequence, F> : sequence_base<transform_view<Sequence, F> >
  81. #endif
  82. {
  83. typedef transform_view_tag fusion_tag;
  84. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  85. typedef mpl::true_ is_view;
  86. typedef typename traits::category_of<Sequence>::type category;
  87. typedef typename result_of::begin<Sequence>::type first_type;
  88. typedef typename result_of::end<Sequence>::type last_type;
  89. typedef typename result_of::size<Sequence>::type size;
  90. typedef Sequence sequence_type;
  91. typedef F transform_type;
  92. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  93. transform_view(Sequence& in_seq, F const& in_f)
  94. : seq(in_seq)
  95. , f(in_f)
  96. {}
  97. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  98. first_type first() const { return fusion::begin(seq); }
  99. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  100. last_type last() const { return fusion::end(seq); }
  101. typename mpl::if_<traits::is_view<Sequence>, Sequence, Sequence&>::type seq;
  102. transform_type f;
  103. };
  104. }}
  105. #ifdef _MSC_VER
  106. # pragma warning(pop)
  107. #endif
  108. #endif