prior_impl.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_PRIOR_IMPL_20060124_2006)
  8. #define FUSION_PRIOR_IMPL_20060124_2006
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/fusion/view/zip_view/zip_view_iterator_fwd.hpp>
  11. #include <boost/fusion/iterator/prior.hpp>
  12. #include <boost/fusion/algorithm/transformation/transform.hpp>
  13. #include <boost/fusion/support/unused.hpp>
  14. #include <boost/mpl/eval_if.hpp>
  15. #include <boost/mpl/identity.hpp>
  16. #include <boost/type_traits/is_same.hpp>
  17. #include <boost/type_traits/remove_reference.hpp>
  18. #include <boost/type_traits/remove_const.hpp>
  19. namespace boost { namespace fusion {
  20. struct zip_view_iterator_tag;
  21. namespace detail
  22. {
  23. struct poly_prior
  24. {
  25. template<typename Sig>
  26. struct result;
  27. template<typename It>
  28. struct result<poly_prior(It)>
  29. {
  30. typedef typename remove_const<
  31. typename remove_reference<It>::type>::type it;
  32. typedef typename mpl::eval_if<is_same<it, unused_type>,
  33. mpl::identity<unused_type>,
  34. result_of::prior<it> >::type type;
  35. };
  36. template<typename It>
  37. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  38. typename result<poly_prior(It)>::type
  39. operator()(const It& it) const
  40. {
  41. return fusion::prior(it);
  42. }
  43. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  44. unused_type operator()(unused_type const&) const
  45. {
  46. return unused_type();
  47. }
  48. };
  49. }
  50. namespace extension
  51. {
  52. template<typename Tag>
  53. struct prior_impl;
  54. template<>
  55. struct prior_impl<zip_view_iterator_tag>
  56. {
  57. template<typename Iterator>
  58. struct apply
  59. {
  60. typedef zip_view_iterator<
  61. typename result_of::transform<typename Iterator::iterators, detail::poly_prior>::type,
  62. typename Iterator::category> type;
  63. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  64. static type
  65. call(Iterator const& it)
  66. {
  67. return type(
  68. fusion::transform(it.iterators_, detail::poly_prior()));
  69. }
  70. };
  71. };
  72. }
  73. }}
  74. #endif