begin_impl.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_BEGIN_IMPL_20060123_2147)
  8. #define FUSION_BEGIN_IMPL_20060123_2147
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/sequence/intrinsic/begin.hpp>
  11. #include <boost/fusion/view/zip_view/zip_view_iterator_fwd.hpp>
  12. #include <boost/fusion/algorithm/transformation/transform.hpp>
  13. #include <boost/type_traits/remove_reference.hpp>
  14. #include <boost/type_traits/is_reference.hpp>
  15. #include <boost/type_traits/is_same.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include <boost/mpl/eval_if.hpp>
  18. #include <boost/mpl/identity.hpp>
  19. #include <boost/fusion/support/unused.hpp>
  20. namespace boost { namespace fusion {
  21. struct zip_view_tag;
  22. namespace detail
  23. {
  24. struct poly_begin
  25. {
  26. template<typename T>
  27. struct result;
  28. template<typename SeqRef>
  29. struct result<poly_begin(SeqRef)>
  30. : mpl::eval_if<is_same<SeqRef, unused_type const&>,
  31. mpl::identity<unused_type>,
  32. result_of::begin<typename remove_reference<SeqRef>::type> >
  33. {
  34. BOOST_MPL_ASSERT((is_reference<SeqRef>));
  35. };
  36. template<typename Seq>
  37. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  38. typename result<poly_begin(Seq&)>::type
  39. operator()(Seq& seq) const
  40. {
  41. return fusion::begin(seq);
  42. }
  43. template<typename Seq>
  44. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  45. typename result<poly_begin(Seq const&)>::type
  46. operator()(Seq const& seq) const
  47. {
  48. return fusion::begin(seq);
  49. }
  50. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  51. unused_type operator()(unused_type const&) const
  52. {
  53. return unused_type();
  54. }
  55. };
  56. }
  57. namespace extension
  58. {
  59. template<typename Tag>
  60. struct begin_impl;
  61. template<>
  62. struct begin_impl<zip_view_tag>
  63. {
  64. template<typename Sequence>
  65. struct apply
  66. {
  67. typedef zip_view_iterator<
  68. typename result_of::transform<typename Sequence::sequences, detail::poly_begin>::type,
  69. typename Sequence::category> type;
  70. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  71. static type
  72. call(Sequence& sequence)
  73. {
  74. return type(
  75. fusion::transform(sequence.sequences_, detail::poly_begin()));
  76. }
  77. };
  78. };
  79. }
  80. }}
  81. #endif