end_impl.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2006 Dan Marsden
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(FUSION_END_IMPL_20060123_2208)
  8. #define FUSION_END_IMPL_20060123_2208
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/view/zip_view/zip_view_iterator_fwd.hpp>
  11. #include <boost/fusion/sequence/intrinsic/end.hpp>
  12. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  13. #include <boost/fusion/sequence/intrinsic/size.hpp>
  14. #include <boost/fusion/sequence/intrinsic/front.hpp>
  15. #include <boost/fusion/iterator/advance.hpp>
  16. #include <boost/fusion/algorithm/transformation/transform.hpp>
  17. #include <boost/type_traits/remove_reference.hpp>
  18. #include <boost/type_traits/is_reference.hpp>
  19. #include <boost/mpl/assert.hpp>
  20. #include <boost/mpl/min.hpp>
  21. #include <boost/mpl/eval_if.hpp>
  22. #include <boost/mpl/identity.hpp>
  23. #include <boost/type_traits/is_same.hpp>
  24. namespace boost { namespace fusion {
  25. struct zip_view_tag;
  26. namespace detail
  27. {
  28. template<typename SeqRef, typename M>
  29. struct get_endpoint
  30. {
  31. typedef typename remove_reference<SeqRef>::type Seq;
  32. typedef typename result_of::begin<Seq>::type begin;
  33. typedef typename result_of::advance<begin, M>::type type;
  34. };
  35. template<typename M>
  36. struct endpoints
  37. {
  38. template<typename T>
  39. struct result;
  40. template<typename M1, typename SeqRef>
  41. struct result<endpoints<M1>(SeqRef)>
  42. : mpl::eval_if<is_same<SeqRef, unused_type const&>,
  43. mpl::identity<unused_type>,
  44. get_endpoint<SeqRef, M> >
  45. {
  46. BOOST_MPL_ASSERT((is_reference<SeqRef>));
  47. };
  48. template<typename Seq>
  49. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  50. typename result<endpoints(Seq&)>::type
  51. operator()(Seq& seq) const
  52. {
  53. return fusion::advance<M>(fusion::begin(seq));
  54. }
  55. template<typename Seq>
  56. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  57. typename result<endpoints(Seq const&)>::type
  58. operator()(Seq const& seq) const
  59. {
  60. return fusion::advance<M>(fusion::begin(seq));
  61. }
  62. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  63. unused_type operator()(unused_type const&) const
  64. {
  65. return unused_type();
  66. }
  67. };
  68. }
  69. namespace extension
  70. {
  71. template<typename Tag>
  72. struct end_impl;
  73. template<>
  74. struct end_impl<zip_view_tag>
  75. {
  76. template<typename Sequence>
  77. struct apply
  78. {
  79. typedef zip_view_iterator<
  80. typename result_of::transform<typename Sequence::sequences, detail::endpoints<typename Sequence::size> >::type,
  81. typename Sequence::category> type;
  82. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  83. static type
  84. call(Sequence& sequence)
  85. {
  86. return type(
  87. fusion::transform(sequence.sequences_, detail::endpoints<typename Sequence::size>()));
  88. }
  89. };
  90. };
  91. }
  92. }}
  93. #endif