zip_view.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_ZIP_VIEW_23012006_0813)
  8. #define FUSION_ZIP_VIEW_23012006_0813
  9. #include <boost/fusion/support/sequence_base.hpp>
  10. #include <boost/fusion/support/unused.hpp>
  11. #include <boost/fusion/iterator/equal_to.hpp>
  12. #include <boost/fusion/view/detail/strictest_traversal.hpp>
  13. #include <boost/fusion/view/zip_view/detail/begin_impl.hpp>
  14. #include <boost/fusion/view/zip_view/detail/end_impl.hpp>
  15. #include <boost/fusion/view/zip_view/detail/size_impl.hpp>
  16. #include <boost/fusion/view/zip_view/detail/at_impl.hpp>
  17. #include <boost/fusion/view/zip_view/detail/value_at_impl.hpp>
  18. #include <boost/fusion/container/vector/convert.hpp>
  19. #include <boost/fusion/algorithm/query/find_if.hpp>
  20. #include <boost/fusion/sequence/intrinsic/end.hpp>
  21. #include <boost/fusion/sequence/intrinsic/size.hpp>
  22. #include <boost/fusion/mpl.hpp>
  23. #include <boost/fusion/algorithm/transformation/remove.hpp>
  24. #include <boost/mpl/assert.hpp>
  25. #include <boost/mpl/not.hpp>
  26. #include <boost/mpl/placeholders.hpp>
  27. #include <boost/mpl/transform_view.hpp>
  28. #include <boost/mpl/at.hpp>
  29. #include <boost/mpl/find_if.hpp>
  30. #include <boost/mpl/equal_to.hpp>
  31. #include <boost/mpl/bool.hpp>
  32. #include <boost/mpl/eval_if.hpp>
  33. #include <boost/type_traits/remove_reference.hpp>
  34. #include <boost/type_traits/is_reference.hpp>
  35. #include <boost/config.hpp>
  36. namespace boost { namespace fusion {
  37. namespace detail
  38. {
  39. template<typename Sequences>
  40. struct all_references
  41. : fusion::result_of::equal_to<typename fusion::result_of::find_if<Sequences, mpl::not_<is_reference<mpl::_> > >::type, typename fusion::result_of::end<Sequences>::type>
  42. {};
  43. struct seq_ref_size
  44. {
  45. template<typename Params>
  46. struct result;
  47. template<typename Seq>
  48. struct result<seq_ref_size(Seq)>
  49. {
  50. static int const high_int = static_cast<int>(
  51. (static_cast<unsigned>(~0) >> 1) - 1);
  52. typedef typename remove_reference<Seq>::type SeqClass;
  53. typedef typename mpl::eval_if<
  54. traits::is_forward<SeqClass>,
  55. result_of::size<SeqClass>,
  56. mpl::int_<high_int> >::type type;
  57. };
  58. // never called, but needed for decltype-based result_of (C++0x)
  59. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  60. template<typename Seq>
  61. typename result<seq_ref_size(Seq)>::type
  62. operator()(Seq&&) const;
  63. #endif
  64. };
  65. struct poly_min
  66. {
  67. template<typename T>
  68. struct result;
  69. template<typename Lhs, typename Rhs>
  70. struct result<poly_min(Lhs, Rhs)>
  71. {
  72. typedef typename remove_reference<Lhs>::type lhs;
  73. typedef typename remove_reference<Rhs>::type rhs;
  74. typedef typename mpl::min<lhs, rhs>::type type;
  75. };
  76. // never called, but needed for decltype-based result_of (C++0x)
  77. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  78. template<typename Lhs, typename Rhs>
  79. typename result<poly_min(Lhs, Rhs)>::type
  80. operator()(Lhs&&, Rhs&&) const;
  81. #endif
  82. };
  83. template<typename Sequences>
  84. struct min_size
  85. {
  86. typedef typename result_of::transform<Sequences, detail::seq_ref_size>::type sizes;
  87. typedef typename result_of::fold<sizes, typename result_of::front<sizes>::type, detail::poly_min>::type type;
  88. };
  89. }
  90. struct zip_view_tag;
  91. struct fusion_sequence_tag;
  92. template<typename Sequences>
  93. struct zip_view : sequence_base< zip_view<Sequences> >
  94. {
  95. typedef typename result_of::remove<Sequences, unused_type const&>::type real_sequences;
  96. BOOST_MPL_ASSERT((detail::all_references<Sequences>));
  97. typedef typename detail::strictest_traversal<real_sequences>::type category;
  98. typedef zip_view_tag fusion_tag;
  99. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  100. typedef mpl::true_ is_view;
  101. typedef typename fusion::result_of::as_vector<Sequences>::type sequences;
  102. typedef typename detail::min_size<real_sequences>::type size;
  103. zip_view(
  104. const Sequences& seqs)
  105. : sequences_(seqs)
  106. {};
  107. sequences sequences_;
  108. };
  109. }}
  110. #endif